Reputation: 6109
I am having back button and edit button on my navigation bar like below
After clicking on the Edit button, I have
My question : how can I disable click on back button when I am in edit mode so that user can not go back previous screen until he or she is done.....
What I am trying is
self.navigationItem.backBarButtonItem.enabled = NO;
but the back button is still clickable
PS : The way I add back button to navigation bar is
self.navigationItem.hidesBackButton = NO;
I can hide back button but I dont want that option...
Please advice me on this issue. Any comments are welcomed here.
Upvotes: 1
Views: 2017
Reputation: 130102
The best solution would be to end edit mode when you are leaving the screen, maybe displaying a confirmation alert first (UIAlertView
with two buttons "Ok" and "Cancel").
However, to answer the question - you would have to create a UIButton
with the same appearance as a back button (using images). Create a UIBarButtonItem
with this button as its custom view and use it in leftBarButtonItem
(note that backBarButtonItem
cannot have custom views).
Then you would be able to set enabled
to NO
on that custom view.
EDIT: I was wrong. UIBarButtonItem
has enabled
property. The problem with disabling the back button was there probably because you were disabling backBarButtonItem
on the wrong navigationItem
. The back button is always defined by the previous controller in the stack.
Upvotes: 2
Reputation: 4180
If the button is blocked maybe you should hide it. Because in my point of view having a unresponsive button is not good for the user.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[UIView animateWithDuration:0.35f animations:^{
self.navigationItem.hidesBackButton = editing;
}];
}
Upvotes: 1
Reputation: 4388
self.navigationItem.backBarButtonItem.enabled = NO;
Where you put the above code. place the above code in edit button's IBAction method.
Upvotes: 0