Here’s my code for creating and displaying a back-button in my UINavigationController:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
backButton.title = @"Home";
self.navigationItem.backBarButtonItem = backButton;
This worked perfectly in iOS 5, but since upgrading to iOS 6 its not working.
To make sure I take care of all possibilities, I’ve placed this code in my viewDidLoad, viewDidAppear, and viewWillAppear – so its in 3 different methods – and its still not showing up. Its also obviously in the rootViewController’s didSelectRowAtIndexPath method – the one from which we are navigating to the other viewControllers.
I do also have a custom graphic in the banner/header of the rootViewController:
// Banner Code:
bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[bannerImageView setImage:[UIImage imageNamed:@"logo-banner@2x.png"]];
[self.navigationController.navigationBar addSubview:bannerImageView];
But again, this worked perfectly well in iOS 5 and didn’t conflict with the back-button. But now I’m just getting the banner/header graphic without the back-button.
One final note: the back button DOES show up for a split-second when I click on the EMPTY space where it SHOULD be. So its there – but you can’t see it until you click on the empty space where it should be. It then shows up for a split-second – but then the App navigates back one screen so it immediately disappears. Very weird.
Any clues?
You’re correct in assuming that your custom header graphic has something to do with your invisible back button (if you remove the header image, notice that the back button will become visible again).
If you aren’t supporting firmwares older than iOS 5, use
setBackgroundImage:forBarMetrics:to customize your header background:(Note the absence of
@2xfrom the image name – your app will know whether to use the standard or retina version of an image automatically.)