2

I upgraded to XCode 4.2. When my app is run in the iOS 4.0 simulator, the navigation bar is displayed on multiple views that are pushed into. When the app is run in the iOS 5.0 simulator and on a device with iOS 5.0, the navigation bar is gone in all the views, and the table views are pushed up to fill that space. The navigation controller is created using the following code:

navigationController = [[UINavigationController alloc] initWithRootViewController:swViewController];

and the views are pushed onto the navigationController like so:

    UIBarButtonItem *backButtonItem       = [[[UIBarButtonItem alloc] initWithTitle:@"NextLevel" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease] ;
    self.navigationItem.backBarButtonItem = backButtonItem;
    [self.navigationController pushViewController:self.listController animated:YES];

The navigationController is added to the window via:

[window addSubview:self.navigationController.view];

Update 1 - It looks like the navigation bar's default in iOS 5 is hidden, so I added

  [[self navigationController] setNavigationBarHidden:NO animated:YES];

and I now see the navigation bar, but no back button as specified in backButtonItem.

Update 2 - I also set the navigationController title, but that doesn't show up either.

         self.navigationController.title       = @"Title";

Is there something that is missing or is needed for the navigation bar to be visible at the top in iOS 5.0?

James Testa
  • 2,901
  • 4
  • 42
  • 60

2 Answers2

1

It's not 100% clear what's wrong. In cases like this (works on older iOS, breaks on upgrade) you were probably doing something wrong all along, but it just happened to work on the older OS.

Just as a guess, I recommend using the UIWindow's rootViewController property instead of the old-style addSubview: call. In other words,

window.rootViewController = self.navigationController;

See if that helps.

benzado
  • 82,288
  • 22
  • 110
  • 138
  • Its quite possible that the reason it broke on iOS 5 was that I was doing something wrong previously. With each upgrade Apple tries to refine the error checking. I added your code above, but that didn't fix it. – James Testa Nov 16 '11 at 04:47
1

I figured it out. I had the following code to hide the Navigation bar when I popped back up as per this SO link

hide_nav_bar

 - (void) viewWillAppear:(BOOL)animated
 {
     [self.navigationController setNavigationBarHidden:YES animated:animated];
     [super viewWillAppear:animated];
 }

Once I commented out this code, then the back button showed up.

Community
  • 1
  • 1
James Testa
  • 2,901
  • 4
  • 42
  • 60