In app delegate, inside didFinishLaunchingWithOptions function, I have the following code to load a view that is a UINavigationController:
UINavigationController *navcon=[[UINavigationController alloc] initWithNibName:@"ThirdView" bundle:[NSBundle mainBundle]];
FirstView *fv=[[FirstView alloc] init];
[navcon pushViewController:fv animated:NO];
[fv release];
[self.window addSubview:navcon.view];
[self.window makeKeyAndVisible];
return YES;
The .xib "ThirdView", that is a UINavigationController View, actually looks like this in the Interface Builder:
But when I run the app, the app looks like this:
Why is the application not loading the Navigation Bar design of "ThirdView.xib" UINavigationController as I have designed it in the Interface Builder?
Update: Here is how "FirstView" looks like in IB:
I don't believe that what you are trying to do is valid. UINavigationController is intended to be a container for other views. You create the UINavigationController and then add your content to it by pushing view controllers onto it with pushViewController:animated:. It is the pushed view controllers that are created with .xib files.
Each UIViewController in a Navigation controller is responsible for providing content to be display on the navigation bar.
In your view didLoad method of your FirstView do the following
self.navigationItem.title = @"your title";
But can you also post how your FirstView look in IB?
Personally I never setup the navigation bar in IB. Here how you can set 2 button in code for your Navigation bar
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
This code come from a UITableViewController subclass.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.