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 :
Customize it like you said
Add a
UINavigationBar
and useUIVavigationItem
, and then use `self.editbuttonitem -> read about it here
Idan
2010-09-01 07:05:18
But how can I implement the multiple delete action?I can detect the UITableViewCellEditingStyleDelete, but it only detect one only.
Ted Wong
2010-09-01 07:07:08
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
2010-09-01 07:09:45
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
2010-09-01 07:10:20