UINavigationController as child view of UIViewCont

2019-09-11 07:13发布

问题:

I have an application that isn't nav based. So there is no UINavigationController in the App Delegate. However, I need to switch to a UINavigationController for a piece of the application. Steps I currently took...

  • Create a new Class that extends UIViewController
  • Added a UINavigationController via IB
  • Told IB that the new UIViewController's view is the view for the UINavigationController

The problem now is that the File's Owner needs it's view set. But via IB there is no way to specify this. So obviously, I'm not going about this the right way. Any tips in the right direction are much appreciated.

回答1:

connect your navigation controller in IB (in this case navController) and init it with your controller:

MessageViewController *mView = [[MessageViewController alloc]initWithNibName:@"MessageView" bundle:nil];
mView.navController = [[UINavigationController alloc] initWithRootViewController:mView];
[self presentModalViewController:mView.navController animated:YES];
[mView release];