Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 1.03 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Add row to UITableView crash if initially empty table
  2. NSArray *indexPaths = [NSArray arrayWithObjects: [NSIndexPath indexPathForRow:[commentsArray count] inSection:0], nil];
  3.  
  4. [commentsTableView beginUpdates];
  5.  
  6. [commentsArray addObject:newestEntry];
  7. [commentsTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
  8.  
  9. [commentsTableView endUpdates];
  10.  
  11. [commentsTableView scrollToBottom:YES];
  12.        
  13. *** 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).'
  14.        
  15. NSAssert(commentsArray, @"commentsArray is nil");
  16. [commentsArray addObject:newestEntry];
  17.        
  18. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  19.  
  20.     return [commentsArray count];
  21. }