iphone - Expand section UITableview getting crash when reloadSections -


trying expand sections each section have 2 rows when expanded. giving crash. below code trying.

-(nsinteger) numberofsectionsintableview:(uitableview *)tableview { return [self.marrques count]; }  -(nsinteger) tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { if(!helpon)     return 1; else     if(section == selectedcellindexpath)     {     return 2;     }     else{         return 1;     } return 1; }  -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cellidentifier"; uitableviewcell *cell; cell = [self.mhelptable dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) {     cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } else{     cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; }  uiview* mybackgroundview = [[uiview alloc] initwithframe:cgrectzero]; mybackgroundview.backgroundcolor = [uicolor colorwithred:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0]; cell.backgroundview = mybackgroundview; //[cell addsubview:mybackgroundview];  if(!helpon) {     cell.textlabel.text = [self.marrques objectatindex:indexpath.section]; } else { if(indexpath.row == 0)     {     cell.textlabel.text = [self.marrques objectatindex:indexpath.section];     } else{     cell.textlabel.text = [self.marrans objectatindex:indexpath.section];     } }  cell.selectionstyle = uitableviewcellselectionstylenone; cell.accessorytype = uitableviewcellaccessorydisclosureindicator;  return cell; }  -(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { helpon = !helpon;  int ind = indexpath.section; if(ind == selectedcellindexpath) { } else{     helpon = 1; } if(helpon) {     selectedcellindexpath = indexpath.section; [self.mhelptable reloadsections:[nsindexset indexsetwithindex:indexpath.section] withrowanimation:uitableviewrowanimationfade]; } else {     if(indexpath.row == 0)     {     //selectedcellindexpath = indexpath.section;     [self.mhelptable reloadsections:[nsindexset indexsetwithindex:indexpath.section] withrowanimation:uitableviewrowanimationfade];     } } } 

error :

invalid update: invalid number of rows in section 0. number of rows contained in existing section after update (2) must equal number of rows contained in section before update (1), plus or minus number of rows inserted or deleted section (0 inserted, 0 deleted) , plus or minus number of rows moved or out of section (0 moved in, 0 moved out).'

as changing number of cells @ section, need wrap reload operation beginupdates , endupdates specify cells insertion , removal insertrowsatindexpaths:withrowanimation , deleterowsatindexpaths:withrowanimation:.

alternatively can use 'reloaddata` reload cells, there problems either animation or user experience if use it.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -