views:

3329

answers:

3

In my table view controller there is

self.navigationItem.leftBarButtonItem = self.editButtonItem;

which produces a regular edit/done button at the top left corner. Hence, once the user clicks "Edit", the button caption changes to "Done" and the table entries may be deleted or reordered. I would like to get notified once the user actually clicks "Done". Is there a hook for that?

Background: I'd like to persist the order of the entries i.e. next time the user pulls up this view I'd like to present the entries in the least recently used order.

+1  A: 

This is the standard way to get notified when a bar button has been pushed:

self.editButtonItem.target = self;
self.editButtonItem.action = @selector(buttonPushed:);

...

- (void) buttonPushed:(id)sender
{
// do stuff here
}
Ramin
Well, I know that. The point is that I don't want to interfere with what the button already does (modify list entries, toggle its caption, etc.). I simply would like to know when it is clicked in its "Done" state.
Marcel
UIBarButtonItems don't derive from UIControl so you can't just add another target to it. You can always capture the action and maintain the state yourself. It's not that hard. Or else, get the buttonPushed call (above) then set an 'ignore' flag and turn around and synthesize a one-time event back at the button to let it do its thing. Details on synthesizing touch events here: http://cocoawithlove.com/2008/10/synthesizing-touch-event-on-iphone.html
Ramin
+3  A: 

for those who are still interesed in this question (or answer :P)

UITableView API

revealed that there is a - (void)setEditing:(BOOL)editing animated:(BOOL)animate method these method is called every time this edit/done button is pressed. you have to simply check by the (BOOL)editing parameter wich one was used. last but not least you have to call the proper method from the originally edit/done button.

simply add this method to your uitableview class

- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
    [super setEditing:editing animated:animate];
    if(editing)
    {
        NSLog(@"editMode on");
    }
    else
    {
        NSLog(@"Done leave editmode");
    }
}
dustin.b
A: 

It is possible to change the action. After edit button clicked it shows delete button, instead it is possible to show reject/verify/modify buttons. And change corresponding action instead of delete option

Thanks Mindus

mindus