3
我對如何將行添加到表視圖有點困惑。嘗試更新我的表視圖中的行數時出錯
我有一個數組,它定期向它添加值。我試圖更新行時每次新的值是使用以下幾行代碼添加到陣列的數量:
// listOfMembers if a
[[self tableView] beginUpdates]; [tableView numberOfRowsInSection:[listOfMembers count]];
[[self tableView] endUpdates];
[[self tableView] beginUpdates];
[tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
[[self tableView] endUpdates];
然而,這並不努力改變的行數..可我誤解如何表更新。我得到這個錯誤:
*** 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 (5) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
崩潰就行了:
[tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
我應該如何更新我的表視圖清楚我在錯誤的方式這樣做。