iphone - deleteRowsAtIndexPaths on heavily-updated model crashes -


a view controller has data model updates , aggressively

a uitableview (storytable) called ever update , reflect changes date.

(changed code reflect single beginupdates endupdates) - still crashes

  [self.storytable beginupdates];                 if([deleteindexpaths count]){                     dlog(@"table refresh delele rows :%@",deleteindexpaths);                      [self.storytable deleterowsatindexpaths:deleteindexpaths withrowanimation:uitableviewrowanimationnone];                   }                  if ([addindexpaths count]){                     dlog(@"table refresh add rows :%@",addindexpaths);                      [self.storytable insertrowsatindexpaths:addindexpaths withrowanimation:uitableviewrowanimationtop];                  }                 if ([changedindexpaths count]){                      dlog(@"table refresh change rows :%@",changedindexpaths);                     [self.storytable reloadrowsatindexpaths:changedindexpaths withrowanimation:uitableviewrowanimationfade ];                  }                 [self.storytable endupdates];                 //[self.storytable endupdates];                 tableisanimating = no;          } 

crashes time time following message: (mostly on deleterowsatindexpaths...)

* assertion failure in -[uitableview _endcellanimationswithcontext:], /sourcecache/uikit/uikit-2380.17/uitableview.m:1070

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 (20) must equal number of rows contained in section before update (20), plus or minus number of rows inserted or deleted section (0 inserted, 10 deleted) , plus or minus number of rows moved or out of section (0 moved in, 0 moved out).'

or :

* terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'attempt insert row 20 section 0, there 20 rows in section 0 after update'

question: how can 1 add protective code prevent crash?

i think problem here when there both deletes, adds , changes mixed @ same time, indexpaths wrong after first -endupdates.

you can try this:

[self.storytable beginupdates]; if([deleteindexpaths count]){    [self.storytable deleterowsatindexpaths:deleteindexpaths withrowanimation:uitableviewrowanimationnone]; } if ([addindexpaths count]){    [self.storytable insertrowsatindexpaths:addindexpaths withrowanimation:uitableviewrowanimationtop]; } if ([changedindexpaths count]){    [self.storytable reloadrowsatindexpaths:changedindexpaths withrowanimation:uitableviewrowanimationfade ]; } [self.storytable endupdates]; 

this way indexpaths valid through operations.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -