How can I impose additional behavior when in the edit mode of a table view controller. I want to implement a behavior just like the Recents section of Phone application where once Edit is pressed a Clear button appears on the left. How can I do this?
In viewDidLoad I have
self.navigationItem.rightBarButtonItem = self.editButtonItem;
And therefore when Edit button is pressed I get the red circles that gives me the deleting capability which works fine and then
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
is called automatically so the tableview and the underlying data is updated. They all work fine. But if I modify the content of viewDidLoad like the following
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.navigationItem.rightBarButtonItem.action = @selector(editPressed:);
and implement
- (IBAction)editPressed:(UIButton *)sender
{
NSLog(@"In Edit Pressed");
}
Pressing Edit button will take me to editPressed: but now the normal behavior of Edit for tableview is lost.
When using the default view controller edit button, you can override the method
- (void)setEditing:(BOOL)editing animated:(BOOL)animatedof theUITableViewController. So, you can put the code in this method, andsuperit. So, your code could look like this: