Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iPhoneSpain

macrumors newbie
Original poster
Sep 27, 2009
28
0
Hi,

I would like to put a button that is able to do the same that the edit button that is provided by every uitableview:

self.navigationItem.leftBarButtonItem = self.editButtonItem;

So I´ve created a uibarbuttonitem with its ibaction method but...what do I have to write inside that ibaction method to have the same functionality that I have when I press the edit button?

Thanks in advance!!!
 
You should just need to toggle set editing to on (or off).

Depending on if your view controller is a table view controller or not, you should just be able to do something like the following:

Code:
- (IBAction)customEditButtonWasPressed:(id)sender {
    if (self.editing) {
        // Toggle editing off as it is already on
        [self setEditing:NO animated:YES];
    } else {
        // Toggle editing on
        [self setEditing:YES animated:YES];
    }
}
You may need to actually set the editing of the table view itself instead if you are not using a tableview controller, eg:

Code:
[self.mainTableView setEditing:YES animated:YES];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.