iphone - App crashing on deleting a row -
my table used list rows core data. works fine, have used 2 types of data load on same table view. data types change on account of scope button change. 2 scope buttons 1 displays completed tasks while other displays pending taks. can search, update on table. while completed list of datas editable , can deleted, works fine , gives error such,
serious application error. exception caught delegate of nsfetchedresultscontroller during call -controllerdidchangecontent:. *** - [nsmutablearray insertobject:atindex:]: index 4 beyond bounds empty array userinfo (null)
the fetch result controller initialised as,
- (nsfetchedresultscontroller *)fetchedresultscontrollerwithpredicate:(nspredicate *)predicate{ if (self.fetchedresultscontrol != nil) { nslog(@"here outside"); return self.fetchedresultscontrol; }
the code load cell tableview :
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; customcell *cell =(customcell *) [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { nsarray *toplevelobjects=[[nsbundle mainbundle] loadnibnamed:@"customcell" owner:nil options:nil]; (id currentobject in toplevelobjects) { if([currentobject iskindofclass:[uitableviewcell class]]){ cell=(customcell *)currentobject; break; } } } [self configurecell:cell atindexpath:indexpath]; return cell;
}
and update method called nsfetchedresultscontrollerdelegate as;
- (void)controllerwillchangecontent:(nsfetchedresultscontroller *)controller { [self.listingtable beginupdates]; nslog(@"changed content"); } - (void)controller:(nsfetchedresultscontroller *)controller didchangesection:(id < nsfetchedresultssectioninfo>)sectioninfo atindex:(nsuinteger)sectionindex forchangetype:(nsfetchedresultschangetype)type { switch(type) { case nsfetchedresultschangeinsert: [self.listingtable insertsections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangedelete: [self.listingtable deletesections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade]; break; }
}
- (void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type newindexpath:(nsindexpath *)newindexpath { nslog(@"changed content switch case"); uitableview *tableview = self.listingtable; switch(type) { case nsfetchedresultschangeinsert: [self.listingtable insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationtop]; break; case nsfetchedresultschangedelete: [self.listingtable deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangeupdate: [self configurecell:(customcell *)[tableview cellforrowatindexpath:indexpath] atindexpath:indexpath]; break; case nsfetchedresultschangemove: [self.listingtable deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; [self.listingtable insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationfade]; break; } } - (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller { nslog(@"changed content"); [self.listingtable endupdates]; }
i don't see obvious errors swapping out 2 logical tables in 1 tableview dangerous design because have careful tableview knows logical table has been changed.
the error getting suggest tableview configuring using 1 index of 1 logical table accessing array of second logical table shorter.
your immediate solution closely @ methods numberofsections
, numberofrowsinsection
make sure update when switched logical tables.
the best design solution use 2 separate tableviews own separate data source , swap them out needed.
Comments
Post a Comment