Alex Rivera | Logout

How to detect edit mode on iPhone UITableView

Asked 2009-11-21T17:04:36.850
14

For my iPhone app, I have an editable (for delete) table view. I'd like to be able to detect that the user has clicked the "Edit" button. See this image: http://grab.by/It0

From the docs, it looked like if I implemented :

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

then I could detect it (although from the name of the method, I wouldn't think that). This proved not to work.

Any ideas on detecting this? The reason I want to is I want to hook up a "Delete all" button in the upper left hand corner when in delete mode.

thanks

Edit
Report

1 Answer

16

When subclassing a tableviewcontroller (what most people are going to be doing most of the time since you have to override it's delegate methods just to put data into it...) you can just override the setEditing:animated: method to grab editing state changes.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    NSLog(@"Editing %i", editing);
    [super setEditing:editing animated:animated];
}

That passes the state change along to the super class, but lets you jump in the middle and detect the change, or alter it if you wanted...

answered 2012-02-19T17:07:29.187

Your Answer