1. 程式人生 > >UITableView 左滑刪除

UITableView 左滑刪除

// tableView 編輯

-  (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

if(indexPath.row == self.sightModel.equipmentList.count){

returnNO;

    }

else{

returnYES;

    }

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(

NSIndexPath *)indexPath

{

returnUITableViewCellEditingStyleDelete;

}

- (void)tableView :(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

NSMutableArray *equipmentList = [[NSMutableArrayalloc]initWithArray:self.

sightModel.equipmentList];

    [equipmentList removeObjectAtIndex:indexPath.row];

self.sightModel.equipmentList = equipmentList;

//    [self.tableView reloadData];

    [self.tableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

/** 2. TableView

刪除一個cell. */

//    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];

}