Reputation: 7068
I'm stumped. I'm using a UINavigationController and on one view I'm trying to hide the back button. But when I do that it hides the back button on the next level of views also.
In - (void)viewWillAppear:(BOOL)animated
I have:
[self.navigationItem setHidesBackButton:YES animated:NO];
And in - (void)viewWillDisappear:(BOOL)animated
I have:
[self.navigationItem setHidesBackButton:NO animated:NO];
This just makes the back button appear just before it leaves (which seems like that is the correct functionality of that call). Therefore I tired to put
[self.navigationItem setHidesBackButton:NO animated:NO];
in - (void)viewWillAppear:(BOOL)animated
of the next view, and that still doesn't work.
This is a little confusing since self.navigationItem.backBarButtonItem
is a reference of what that view's back button will be when it is the view just under the top view (ref). But self.navigationItem.hidesBackbutton
is whether the back button is shown when it is the top view (ref). So does anyone have any idea why it would hide the back button of the next view?
Another strange thing is it works when I go another view down. For a more visual representation, lets say I have the following views:
A > B > C > D
B is the view I'm concerned about. I want to hide the back button which would go to A. When I do that it hides the back button on C also. But if I do down to D, the back button shows up and then everything acts as it "should." That is, I can go back to C, then Back to B. B has it's back button hidden and if I go back into C the back button shows up like it should.
Any ideas?
Upvotes: 3
Views: 4601
Reputation: 41
To get by this stupid bug, I did not implement setHidesBackButton at all, but in viewDidLoad I put the following:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];
Upvotes: 4
Reputation: 10080
There seems to be some kind of bug regarding the hiding and showing of the back button when dealing with a UINavigationController
. A similar problem to yours is backButton of NavigationController don't appear.
I did some testing regarding this and while I don't have an explanation here are some suggestions that might help you.
setHidesBackButton:animated:
in viewDidAppear:
and not in viewWillAppear:
self.navigationItem.hidesBackButton
anywhere.Upvotes: 9
Reputation: 29524
I guess you know that hiding the back button doesn't prevent a user from clicking on it?
To prevent a click, you have to set it as nil.
self.navigationItem.leftBarButtomItem = nil;
Then you could create a new back button in "B"'s viewWillAppear
method.
Upvotes: 1