Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Had issues with answers 2-4 in iOS 4 (from AnswerBot's answer), and needed a way to load the UINavigationController programmatically (though the NIB method worked)... So I did this:</p> <p>Created a Blank XIB file (don't set file owner), add a UINavigationController (give it your custom UINavigationController's class), change the UINavigationBar to your custom class (here it's CustomNavigationBar), then create the following custom class header (CustomNavigationController.h in this case):</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface CustomNavigationController : UINavigationController + (CustomNavigationController *)navigationController; + (CustomNavigationController *)navigationControllerWithRootViewController:(UIViewController *)rootViewController; @end </code></pre> <p>and custom implementation (CustomNavigationController.mm)</p> <pre><code>#import "CustomNavigationController.h" @interface CustomNavigationController () @end @implementation CustomNavigationController + (CustomNavigationController *)navigationController { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomNavigationController" owner:self options:nil]; CustomNavigationController *controller = (CustomNavigationController *)[nib objectAtIndex:0]; return controller; } + (CustomNavigationController *)navigationControllerWithRootViewController:(UIViewController *)rootViewController { CustomNavigationController *controller = [CustomNavigationController navigationController]; [controller setViewControllers:[NSArray arrayWithObject:rootViewController]]; return controller; } - (id)init { self = [super init]; [self autorelease]; // We are ditching the one they allocated. Need to load from NIB. return [[CustomNavigationController navigationController] retain]; // Over-retain, this should be alloced } - (id)initWithRootViewController:(UIViewController *)rootViewController { self = [super init]; [self autorelease]; return [[CustomNavigationController navigationControllerWithRootViewController:rootViewController] retain]; } @end </code></pre> <p>Then you can just init that class instead of a UINavigationController, and you'll have your custom navigation bar. If you want to do it in a xib, change the class of UINavigationController and UINavigationBar inside of your XIB.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload