问题
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