- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
PFObject *object = [_tdlArray objectAtIndex:(_tdlArray.count - indexPath.row -1)];
[object deleteInBackground];
//found the code for removing a row.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[tableView reloadData];
[object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!succeeded){
[tableView reloadData];
}
}];
}
}
我能夠成功移除數據,但每次點擊刪除按鈕時,我的應用都會崩潰。我認爲這事做與[NSArray arrayWithObject:indexPath]
輕掃即可刪除崩潰時的崩潰
這些錯誤消息
Assertion failure in -[UITableView _endCellAnimationsWithContext:]
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
是否要更新您的內部狀態,以便['的tableView:numberOfRowsInSection:'](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDataSource_Protocol/index.html#//apple_ref/occ/intfm/UITableViewDataSource/tableView:numberOfRowsInSection :)當被問到時會返回正確數量的東西嗎? –
您正在刪除後臺線程中的對象,但立即調用deleteRowsAtIndexPath。一旦對象成功刪除,您需要使用回調並調用deleteRowsAtIndexPath。 – beyowulf
@beyowulf對不起,我沒有得到你在說什麼 –