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
}
}