Hi,
I've been trying to build a very basic navigation controller following the instructions given in:
Interface Builder User Guide (IBUG)
View Controller User Guide in iPhone OS (VCUG)
The problem I have is that this doesn't seem to work. Specifically:
After completing the steps given in the section "Configuring the Views for Additional Navigation Levels" in IBUG and getting something which looks exactly like Figure 3-10 in IBUG (except that the class of ViewController is set to my subclass, MyViewController), I attempt to load the child view using the code:
in the parent ViewController. However, an exception is throw which I've traced down to the fact that the outlet of the View object is not connected to anything (the ViewController view-outlet is connected to the View object however). Changing the File's Owner to MyViewController, and linking the View object's outlet to it solves the problem somewhat and the view loads, EXCEPT for the title. I've tried changing the Title attributes in ViewController and the NavigationItem, but on loading the view, the title is still blank. In the end, I've had to add the following code block into MyViewController.m to get it to work:
My questions are:
I realise that I've managed to get it to do what I want it do eventually, but I'd like to understand why the other methods didn't work and I had to hack around the "official" steps to getting something simple to work.
Thanks!
I've been trying to build a very basic navigation controller following the instructions given in:
Interface Builder User Guide (IBUG)
View Controller User Guide in iPhone OS (VCUG)
The problem I have is that this doesn't seem to work. Specifically:
After completing the steps given in the section "Configuring the Views for Additional Navigation Levels" in IBUG and getting something which looks exactly like Figure 3-10 in IBUG (except that the class of ViewController is set to my subclass, MyViewController), I attempt to load the child view using the code:
Code:
MyViewController* myVC = [[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]] autorelease];
[[self navigationController] pushViewController:myVC animated:YES];
in the parent ViewController. However, an exception is throw which I've traced down to the fact that the outlet of the View object is not connected to anything (the ViewController view-outlet is connected to the View object however). Changing the File's Owner to MyViewController, and linking the View object's outlet to it solves the problem somewhat and the view loads, EXCEPT for the title. I've tried changing the Title attributes in ViewController and the NavigationItem, but on loading the view, the title is still blank. In the end, I've had to add the following code block into MyViewController.m to get it to work:
Code:
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:@"MyNewTitle"];
}
My questions are:
- Why does following the guide exactly result in the initial crash - is there something I've done wrong?
- How come setting the title ViewController in Interface Builder doesn't work like it said it should do in the User Guides and I had to resort to doing it programmatically?
I realise that I've managed to get it to do what I want it do eventually, but I'd like to understand why the other methods didn't work and I had to hack around the "official" steps to getting something simple to work.
Thanks!