<UITableViewDelegate>
e.g.
//设置表的编辑模式,如insertion , deletion , both or neither
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete; //UITableViewCellEditingStyleInsert | UITableViewCellEditingStyleNone
}
//点击自身navigationItem中的editButton时调用
- (void) setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];
[self.myTableView setEditing:editing animated:animated]; //当editing=YES时会调用tableView:editingStyleForRowAtIndexPath: ,otherwise no
}
//执行所请求的编辑操作
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)
editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete){
[self.arraySourceRows removeObjectAtIndex:indexPath.row]; //从数据源删除dataRow
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; //表再删除dataRow
}
}
- (void)viewDidLoad{
[super viewDidLoad];
[self.navigationItem setLeftBarButtonItem:self.editButtonItem animated:NO];
//navigationItem自带的编辑项editButtonItem,表所在的控制器是置于NavigationController中
self.myTableView = 。。。。。
[self.view addSubview:self.myTableView];
}