【发布时间】:2023-03-29 23:50:02
【问题描述】:
我有一个 tableView,我想允许编辑和删除行。我让它进入编辑模式很好。但是当我按下删除按钮时,它不会触发事件以使其删除行吗?
这是我的代码:
- (IBAction)editTable:(id)sender {
if(self.editing) {
[super setEditing:NO animated:NO];
[self.tableView setEditing:NO animated:NO];
[self.tableView reloadData];
[self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
} else {
[super setEditing:YES animated:YES];
[self.tableView setEditing:YES animated:YES];
[self.tableView reloadData];
[self.navigationItem.rightBarButtonItem setTitle:@"Done"];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyleforRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"HIT THIS BABY");
NSUInteger row = [indexPath row];
[accountsArray removeObjectAtIndex:row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
【问题讨论】:
标签: ios cocoa-touch uitableview