views:

21

answers:

2

I would like to add a UIBarButtonItem which is titled "edit", when I click the "edit", I can select the row to delete. Is there any simple solution on Apple API already? or I need to customize made the UITableView and the action myself? thank you.

A: 

You have 2 options :

  1. Customize it like you said

  2. Add a UINavigationBar and use UIVavigationItem , and then use `self.editbuttonitem -> read about it here

Idan
But how can I implement the multiple delete action?I can detect the UITableViewCellEditingStyleDelete, but it only detect one only.
Ted Wong
I'm not sure I understand your question. The table view come pre- configured with the ability to delete cell when you enter edit mode. Is there something unique that you're trying to achieve ?
Idan
A: 

Are you subclassing UITableViewController? If so:

You need to add an edit button somewhere, like the navigation bar:

- (void)viewDidLoad
{
    ...
    self.navigationItem.leftBarButtonItem = self.editButtonItem;
    ...
}

And add this function to your view controller:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated]; // must be called first according to Apple docs

    [self.tableView setEditing:editing animated:animated];
}

You probably also want to set the editing style for the table row:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.editing)
    {
        return UITableViewCellEditingStyleDelete;
    }
    else
    {
        return UITableViewCellEditingStyleNone;
    }
}
Shaggy Frog