viewTableView =[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
[viewTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseIdentifier];
// [tableView setEditing:YES];
// viewTableView.allowsMultipleSelectionDuringEditing=YES;
viewTableView.delegate=self;
viewTableView.dataSource=self;
[self.view addSubview: viewTableView];
//导航条的编辑按钮
self.navigationItem.rightBarButtonItem = self.editButtonItem;
//重写编辑的方法 (重点除非类继承tableview或者tableviewControllers否则都要重写这个方法来进入编辑状态)
-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[viewTableView setEditing:editing animated:animated];
}
//选择删除的cell前面带圆圈的选择删除(重点)
#pragma mark - Table view data source
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete| UITableViewCellEditingStyleInsert;
}
//删除添加代理
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
// [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}