Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try to put <code>self.navigationItem.hidesBackButton = NO;</code> into the init method or anywhere before the pushViewController call.</p> <p>ViewDidLoad is called when you ask the controller for the view for the first time, that means, it is probably called from <code>[self.navigationController pushViewController:c animated:YES]</code>. But note that the navigation bar is not part of your view, it is created and handled by <code>UINavigationController</code>, so basically it can exist and be drawn even before viewDidLoad and viewDidAppear is called. If you update navigation bar there, it doesn't get actually repainted.</p> <p>Edit 1: Revisited after reading the documentation for <code>[UIViewController navigationItem]</code></p> <blockquote> <p>You should avoid tying the creation of bar button items in your navigation item to the creation of your view controller’s view. The navigation item of a view controller may be retrieved independently of the view controller’s view. For example, when pushing two view controllers onto a navigation stack, the topmost view controller becomes visible, but the other view controller’s navigation item may be retrieved in order to present its back button. To ensure the navigation item is configured, you can override this property and add code to load the bar button items there or load the items in your view controller’s initialization code.</p> </blockquote> <p>Edit 2: Revisited after reading the comment that my solution does not work. Working code (iOS 5, ARC):</p> <pre><code> // // TestAppDelegate.m // NavigationTest // // Created by Sulthan on 10/25/11. // Copyright (c) 2011 StackOverflow. All rights reserved. // #import "TestAppDelegate.h" @interface TestAppDelegate () @property (nonatomic, strong, readwrite) UINavigationController* navigationScreen; @property (nonatomic, strong, readwrite) UIViewController* screen1; @property (nonatomic, strong, readwrite) UIViewController* screen2; @property (nonatomic, strong, readwrite) UIViewController* screen3; @end @implementation TestAppDelegate @synthesize window = window_; @synthesize navigationScreen = navigationScreen_; @synthesize screen1 = screen1_; @synthesize screen2 = screen2_; @synthesize screen3 = screen3_; - (UIViewController*)createTestScreenWithLabel:(NSString*)label { CGRect bounds = [[UIScreen mainScreen] bounds]; UIViewController* screen = [[UIViewController alloc] init]; screen.view = [[UILabel alloc] initWithFrame:bounds]; screen.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); ((UILabel*) screen.view).textAlignment = UITextAlignmentCenter; ((UILabel*) screen.view).text = label; return screen; } - (void)pushThirdScreen { if (!self.screen3) { self.screen3 = [self createTestScreenWithLabel:@"Screen 3"]; self.screen3.navigationItem.hidesBackButton = NO; } [self.navigationScreen pushViewController:self.screen3 animated:YES]; } - (void)pushSecondScreen { self.screen2 = [self createTestScreenWithLabel:@"Screen 2"]; self.screen2.navigationItem.hidesBackButton = YES; UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithTitle:@"Go" style:UIBarButtonItemStyleBordered target:self action:@selector(pushThirdScreen)]; self.screen2.navigationItem.rightBarButtonItem = button; [self.navigationScreen pushViewController:self.screen2 animated:YES]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ CGRect bounds = [[UIScreen mainScreen] bounds]; self.screen1 = [self createTestScreenWithLabel:@"Screen 1"]; self.navigationScreen = [[UINavigationController alloc] initWithRootViewController:self.screen1]; self.window = [[UIWindow alloc] initWithFrame:bounds]; self.window.backgroundColor = [UIColor whiteColor]; [self.window addSubview:self.navigationScreen.view]; [self.window makeKeyAndVisible]; [self performSelector:@selector(pushSecondScreen) withObject:nil afterDelay:3.0]; return YES; } @end </code></pre> <p>Edit 3: Revisited after noticing that you are speaking mainly about iOS 4.2. I can't currently test it on any iOS 4.2 but I know about a possible workaround. You can always hide the navigation bar in your UINavigationController and just put a separate navigation bar into each screen. You will have absolute control over them and you can even edit them in Interface Builder.</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