Nactus
Nactus

Reputation: 712

UITableView --> Editing mode

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.

Upvotes: 1

Views: 3298

Answers (2)

Dermot
Dermot

Reputation: 1743

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];
}

Upvotes: 6

bilobatum
bilobatum

Reputation: 8918

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.

Upvotes: 5

Related Questions