How to add a Navigation Controller with Interface Builder?

1. Step: Create a new UIViewController:
- Xcode -> New File... -> Cocoa Touch Class -> UIViewController
- Name: MyViewController

2. Step: Drag and drop a "Navigation Controller" (UINavigationController) from the Library to MyViewController.xib

alt text

3.Step: I'm sure, I have to do something to connect the Navigation Controller correctly, isn't it?

4.Step: Try to start the new View Controller as a modal dialog:

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
NSLog(@"navContr: %@", myViewController.navigationController);
[self.navigationController presentModalViewController: myViewController animated:YES]; 

Result: "navContr: nil"

5.Step: You can see the new modal view (MyViewController), but there's no NavigationController and no UINavigationBar.

Thank you very much for your help!


UPDATE 1:

6.Step: I set a new UIViewController (ViewNavi2) as "Root View Controller":
alt text

7.Step: I define a IBOutlet UINavigationController *navigationController in the class MyViewController and configure the xib: Navigation Controller -> Connections -> Referencing Outlets

But my Navigation Controller is still nil :-(

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
NSLog(@"navContr: %@", myViewController.navigationController);
// -> "navContr: nil"
13
задан Matthew Frederick 13 January 2011 в 16:56
поделиться