I saw in the documentation that now you can have an array of items for the leftBarButtonItems and rightBarButtonItems in a UINavigationController and don’t have to create a UIToolBar and set that as the button. I basically want a “Home” button on the left next to the “back” button of the navigationController. So it would look like:
BackButtonFromNavigationController HomeBarButtonItem
I wasn’t sure how I get the navigationBar’s backButton into my array once I create my HomeButton. I tried this, but I only see the navigationController’s backBarButton:
if ([self.navigationItem respondsToSelector:@selector(setLeftBarButtonItems:)]) {
UIBarButtonItem *hButton = [self createHomeButton];
self.navigationController.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:self.navigationItem.backBarButtonItem, hButton, nil];
}
Edited per smparkes response:
if ([self.navigationItem respondsToSelector:@selector(leftItemsSupplementBackButton)]) {
self.navigationItem.leftItemsSupplementBackButton = YES;
self.navigationItem.leftBarButtonItem = homeBBI;
}
I know homeBBI is created properly as I have it in my UIToolBar as the rightBarButtonItem prior to iOS 5. Now I’m just trying to move it to the left and I used the same button to see if it would work but it doesn’t seem to work still…
Don’t put the back button in the array. Use
leftItemsSupplementBackButtonto make the button array add to instead of replace the back button. Once you’ve done that, it doesn’t sound like you even need an array.I think you’re getting the behavior you are seeing because your button array is empty. You’re adding
self.navigationItem.backBarButtonItemwhich is probablynil. You want the back button from the controller one step deeper in the nav stack, not the back button for the current controller.