我正在使用下面的代碼來刷新我剛剛添加了一行的tableview。如果表中至少有1行,則該代碼適用於向表中添加行。但是,如果最初是空表,它會崩潰。如果最初爲空表,將行添加到UITableView崩潰
NSArray *indexPaths = [NSArray arrayWithObjects: [NSIndexPath indexPathForRow:[commentsArray count] inSection:0], nil];
[commentsTableView beginUpdates];
[commentsArray addObject:newestEntry];
[commentsTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
[commentsTableView endUpdates];
[commentsTableView scrollToBottom:YES];
碰撞響應我得到的是:
*** 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 (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).'
有人能幫助我嗎?
非常感謝您。事實證明,當HTTP請求用空字符串響應時,我的數組甚至沒有被分配!謝謝! – quantum 2011-05-12 07:42:02
不客氣!我不喜歡這樣一個事實,即Objective-C允許你在沒有抱怨的情況下用零來做東西,所以在被咬了幾次之後,我開始習慣於在任何一個零對象都會咬我的地方使用NSAssert。我最近被咬得很少;-) – idz 2011-05-12 07:53:50