PDA

View Full Version : Uitableview Edit Button




iPhoneSpain
Dec 8, 2009, 08:12 PM
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 Ive 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!!!



johnnyjibbs
Dec 11, 2009, 05:00 AM
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:


- (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:


[self.mainTableView setEditing:YES animated:YES];