Add row to UITableView crash if initially empty table -


i'm using code below refresh tableview added row into. code works adding row table if there @ least 1 row in table. however, crashes if empty table.

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]; 

the crash response is:

*** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'invalid update: invalid number of rows in section 0.  number of rows contained in existing section after update (0) must equal number of rows contained in section before update (0), plus or minus number of rows inserted or deleted section (1 inserted, 0 deleted).' 

can me?

well, error telling when uikit calls tableview:numberofrowsinsection returning 0 both before , after updates. either have error in method or in update. said in comment previous answer tableview:numberofrowsinsection correct, must update. if commentsarray nil in first update reason might explain things. perhaps try following:

nsassert(commentsarray, @"commentsarray nil"); [commentsarray addobject:newestentry]; 

the assert ignored in release build, use debug build.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -