I\'m developping an app for iOS 4.2+.
I subclassed my UINavigationController
to insert two UIImageView
and make the navigation bar look custom.
Eve
I've come up with a somewhat universal solution: https://stackoverflow.com/a/16831482/171933 It involves a category on UIViewController and requires minimal code to have an image back button on all your screens.
Let's say you have two ViewControllers, A and B, you're pushing B onto the stack when A is topmost, and you want to customize the back button that shows up when B is on top.
Typically, the way to do this is to set ViewController A's navigationItem.backBarButtonItem
.
Instead, what you're doing is to give ViewController B a custom button on the left side of the navbar by setting its navigationItem.leftBarButtonItem
.
You've implemented that approach fine, except that even if you don't set ViewController A's navigationItem.backBarButtonItem
, by default you still get a default back button as well. So that button is probably showing up on top of your custom back button.
If you set ViewController B's navigationItem.hidesBackButton = YES
then you shouldn't have any problem.
And in the future, when you implement custom back buttons, you should do it by setting navigationItem.backBarButtonItem
instead of navigationItem.leftBarButtonItem
. The one adjustment you'll have to make is that with this approach, for example you would use ViewController A's navigationItem
to change the back button that shows up when ViewController B is on top.
UIBarButtonItem *backButton = [UIBarButtonItem new];
[backButton setTitle:@"Back"];
[[self navigationItem] setBackBarButtonItem:backButton];
This code you have to mentioned in previous view controller then only it default back button came in next view controller.
Enjoy!!!