0
我爲我的刪除按鈕編寫了以下代碼,用於從UITableView中刪除選定的行。在Xcode 6中從UITableView手動刪除行
-(IBAction)deleteItems:(id)sender {
NSArray *selectedCells = [self.autoCompleteView indexPathsForSelectedRows];
NSMutableIndexSet *indicesToDelete = [[NSMutableIndexSet alloc] init];
for (NSIndexPath *indexPath in selectedCells) {
[indicesToDelete addIndex:indexPath.row];
}
//arrayFromPlist is NSMutableArray
[autoCompleteView beginUpdates];
[autoCompleteView deleteRowsAtIndexPaths:selectedCells withRowAnimation:UITableViewRowAnimationAutomatic];
[autoCompleteView endUpdates];
[selectedObjects removeObjectsAtIndexes:indicesToDelete];
[autoCompleteView reloadData];
[alertMsg deleteConfirmation:@"Do you want to delete these items?"];
}
請查看我的UITableView和刪除按鈕的圖像。我已將我的UITableview的編輯屬性保存在故事板中的「編輯期間的多重選擇」中。
我收到以下錯誤,當我按在屏幕上顯示的刪除按鈕。
由於未捕獲的異常'NSInternalInconsistencyException',原因:'無效更新:節0中的行數無效。更新(5)後現有節中包含的行數必須等於數在更新之前包含在該部分中的行(5),加上或減去從該部分插入或刪除的行數(0插入,2刪除),加上或減去移入或移出該部分的行數(0搬進來,0搬出去)。'
不知道在刪除按鈕代碼中我的錯誤是什麼。
@matt ...我把[selectedObjects removeObjectsAtIndexes:indicesToDelete];在BeginUpdates下面,但仍然得到與問題中提到的相同的錯誤。 – TheGaME
我不知道'selectedObjects'是什麼或你的模型是如何維護的。但是,在開始「beginUpdates」之前,您必須從模型中刪除行。 – matt
我有2個可變數組:selectedObjects將包含要刪除的項目,autoCompleteData包含要在tableview中顯示的初始數據。 – TheGaME