1

I have an IBAction with a UIButton that enables the edit mode. I'd like to hit the same UIButton and cancel the edit mode. If I use an if-else statement, what do I check for : if(editeModeEnabled)//turn it off, else turn it on ... so I can use the same UIButton for both on and off.

Thanks much.

0

2 Answers 2

6

You can check for the tableView.editing == YES

eg:

if(self.tableView.editing)
//Turn editing off/save changes
else
{
    //Turn editing on
    [self.tableView setEditing:YES animated:YES];
}
1
  • Thanks much, Dermot! I used if ([<tableViewname> isEditing] == YES). I didn't know tableView has a property for this. :D
    – Nactus
    Oct 31, 2013 at 2:27
5

If the button is a bar button item, then the easiest way to toggle the edit button is to set the bar button item to the pre-configured editButtonItem.

- (void)viewDidLoad
{ 
    [super viewDidLoad];

    self.navigationItem.leftBarButtonItem = self.editButtonItem;
}

This special button automatically toggles between "Edit" and "Done"; it also puts the table view in editing mode.

2
  • Hi @bilobatum, is not. Is just a regular button. I already have an IBAction for it (onClick).Thanks.
    – Nactus
    Oct 31, 2013 at 2:17
  • No custom button needed. This is the superior answer.
    – Hyperbole
    Mar 24, 2014 at 2:19

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.