簡體   English   中英

刪除帶有動畫的單元格時發生錯誤

[英]Error Occurs When Deleting Cell with Animation

[[PeopleManager shared] removePersonAtIndex:indexPath.row withGroupIndex:currentGroupIndex];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationNone];

PeopleManager類具有一個人員數組(NSMutableArray)。

我的錯誤不是索引值錯誤。

它正常工作99.9%,沒有錯誤。 但有時會發生錯誤

錯誤代碼

2012-02-03 17:17:53.232電話簿[343:707] *-[UITableView _endCellAnimationsWithContext:],/ SourceCache / UIKit / UIKit-1912.3 / UITableView.m的斷言失敗:m:1046 2012-02-03 17:17: 53.239 PhoneBook [343:707] *由於未捕獲的異常“ NSInternalInconsistencyException”而終止應用程序,原因:“無效更新:部分0中的行數無效。更新(1)之后現有部分中包含的行數必須相等到更新之前該部分中包含的行數(1),加上或減去從該部分插入或刪除的行數(插入0,刪除1),加上或減去移入或刪除該行的行數部分(移入0,移出0)。” 終止稱為拋出異常殺死

如何解決??? 我讀了錯誤代碼。但我不知道如何解決...

您應該在beginUpdates和endUpdates對中包裝好deleteRows ...調用:

[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationNone];
[tableView endUpdates];

並確保您的numberOfRowsForSection:方法返回正確的更新值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM