






// Override to support editing the table view.- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source// 1、應當先刪除對應行的數據// 2、再將對應行的單元格從表視圖中刪除 [self.datasource removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; } 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// 1、現在數組中插入對應的對象// 2、創建對應對象的indexPath// 3、根據indexPath在表視圖中的位置插入對應行 [self.datasource addObject:@"新插入的數據"]; NSIndexPath *insertPath = [NSIndexPath indexPathForRow:self.datasource.count - 1 inSection:0]; [tableView insertRowsAtIndexPaths:@[insertPath] withRowAnimation:UITableViewRowAnimationMiddle]; } }
當表格被拖拽后會相應此方法,

當表格處于編輯狀態時,可以通過以下方法設置相應的表格是否與許被編輯

新聞熱點
疑難解答