我一直在閱讀很多有關更新UITableView後,通過IndexPath和數據源,它似乎是[tableView startUpdates]
刪除行,運行任何更新代碼,然後[tableView endUpdates]
。UITableView細胞不知名地刪除
儘管下面的許多例子,以一個T,並利用[tableView deleteRowsAtIndexPaths:<indexPaths> withRowAnimation:UITableViewRowAnimationTop];
,我似乎無法讓我的行刪除以任何方式,但什麼如下描繪:
http://www.youtube.com/watch?v=l6ov1FR0R4g&feature=youtu.be(基本上,如果有n> 1行,該行將只是閃爍,如果有n = 1行,它將向外滑動,停止,然後消失)。
我真的很喜歡一個更流暢的行爲,就像行可以滑出來一樣。這裏是執行刪除的代碼:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
int idx = [indexPath indexAtPosition:1];
LoLoanedItemDoc *itemDoc = [[self items] objectAtIndex:idx];
// Delete notification
[[UIApplication sharedApplication] cancelLocalNotification:[[itemDoc data] notification]];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
// Remove from datasource
[[self items] removeObject:itemDoc];
[tableView endUpdates];
// Delete folder
[itemDoc deleteDoc];
}
嘗試刪除開始和結束更新,在這種情況下不需要它們。 – rdelmar
我總是先改變我的模型,然後做更新。當你告訴tableview刪除並且模型計數保持不變時,會有這樣的印象,即不這樣做會引發異常。 – danh