iPhone UINavigationController inside UIViewController

拥有回忆 提交于 2020-01-10 20:11:51

问题


Steps:

  • List item
  • Create a project called Nav.
  • Create a new UIViewController BaseViewController (with XIB) and FirstViewController (with XIB).
  • In the NavAppDelegat.h define baseController variable

    @interface NavAppDelegate : NSObject <UIApplicationDelegate> {
    BaseViewController *baseController;
    }
    @property (nonatomic, retain) IBOutlet BaseViewController *baseController; 
    
  • In the NavAppDelegat.m add baseController to the window:

    @synthesize baseController;
    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [self.window addSubview:baseController.view];
    [self.window makeKeyAndVisible];
    return YES;
    }
    
  • Open the BaseViewController.xib file and add UINavigationController, set its Root View Controller class and XIB to FirstViewController (in the inspector).

  • Also connect navigationController variable with the UINavigationController.

I believe this should show me the FirstViewController with the navigation bar. If I do this directly on the MainWindow.xib things are working as I expected but here I can't see the navigation bar. What am I missing? THx!

UPDATE: So the problem is only that in case I use UINavigationController inside some additional controller (BaseViewController.xib here) instead of MainWindow.xib i don't see the navigation bar.


回答1:


I can't tell if you're trying to connect your navigation controller directly to your window, just from a second XIB (which should work) or if you're making your navigation controller a subview of another view, which won't work.

UINavigationController is only intended to be used as either the primary subview of a UIWindow or as a subview of a UITabController. Apple doesn't want you embedding a navigation controller in other contexts.

See Combined View Controller Interfaces in the View Controller Programming Guide for more details.



来源:https://stackoverflow.com/questions/4761935/iphone-uinavigationcontroller-inside-uiviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!