我有这个表链接到一个数据库与"编辑"在右上方。我可以删除滑动,但如果我按编辑按钮什么也没有发生!我的意思是,我在同一个程序中为另一个表编写了类似的调用,当我按下编辑时,出现了一个小的"解锁删除";然后,如果你按下它,你可以删除元素/行…不是在这里!
- (void)viewDidLoad
{
self.title = @"Categorie";
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[self.navigationItem setHidesBackButton:YES animated:YES];
[tableView reloadData];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)_tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// A lot of code...
}
}
你需要告诉tableView开始编辑使用settediting:(BOOL)editing:(BOOL)animate
//Init your editBarButton
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editTable)];
//Init your doneBarButton
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneEditing)];
下面是一个示例动作方法:
- (void)editTable {
if (!self.tableView.editing) [self.tableView setEditing:YES animated:YES];
self.navigationController.rightBarButtonItem = self.doneButton;
}
- (void)doneEditing {
if (self.tableView.editing) [self.tableView setEditing:NO animated:YES];
self.navigationController.rightBarButtonItem = self.editButton;
}