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.
You have 2 options :
Customize it like you said
Add a
UINavigationBar
and useUIVavigationItem
, and then use `self.editbuttonitem -> read about it here
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;
}
}
精彩评论