Try putting self.navigationItem.hidesBackButton = NO; to the init method or anywhere before pushViewController is called.
ViewDidLoad is called when you request the controller for the first time, which means it is probably called from [self.navigationController pushViewController:c animated:YES] . But note that the navigation bar is not part of your view, it is created and processed by the UINavigationController , so in principle it can exist and be drawn even before calling viewDidLoad and viewDidAppear. If you update the navigation bar there, it will not actually be repainted.
Edit 1: Repeat after reading the documentation for [UIViewController navigationItem]
You should not associate the creation of panel elements in a navigation element with the creation of the view of your view controllers. The view controller navigation element can be obtained regardless of the type of view controllers. For example, when two view controllers are pressed on the navigation stack, the top view controller becomes visible, but another visibility manager navigation element can be retrieved to present its return button. To customize a navigation element, you can override this property and add code to load elements of the bar panel or load elements into the initialization code of your controller.
Edit 2: Repeat after reading the comment that my solution is not working. Work Code (iOS 5, ARC):
// // 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
Edit 3: Repeat, noticing that you are talking mainly about iOS 4.2. Currently, I cannot test it on any iOS 4.2, but I know of a possible workaround. You can always hide the navigation bar in your UINavigationController and simply place a separate navigation bar on each screen. You will have absolute control over them, and you can even edit them in Interface Builder.
Sulthan
source share