I have a UIBarButtonItem
in the top right which says 'Edit'. When clicked, this code is called - I know so because the button is emboldened. However, the button's title does not change. Here is my code:
// set to not editing and change buttons
[self setEditing:YES animated:YES];
UIBarButtonItem *doneButton = (UIBarButtonItem *)sender;
[doneButton setTitle:@"Done"];
[doneButton setStyle:UIBarButtonItemStyleDone];
self.navigationItem.rightBarButtonItem = doneButton;
Edit 2:
The following code is doing what I want, however the first time I click the edit button, nothing happens.
-(void)editButton:(id)sender {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style: UIBarButtonItemStylePlain target:self action:@selector(edit:)];
}
-(void) edit:(UIBarButtonItem *) barBtnItem
{
// if not editing
if (![self isEditing])
{
[self setEditing:YES];
barBtnItem.tag = 1;
[self.navigationItem.rightBarButtonItem setTitle:@"Done"];
}
else
{
[self setEditing:NO];
barBtnItem.tag = 0;
[self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
}
}
From "title" property on the UIBarButtonItem reference
Check this qn also
The simplest solution: Just change the BarButtonItem's identifier to custom.
Just do this
Just change state according to click. simple thing.
What about this:
I think it does pretty much what you want it to do.
It changes to "Done" when tapped, and then back to "Edit" when tapped again. Furthermore it sets the view controllers editing property accordingly.
You can do it via code as well as follows
Change type from System:Edit to Custom