objective c - How to apply multiple arrays in expandable tableview in ios -


hi have tried apply multiple arrays in expandable tableview.

but when run code it's showing exception.

exception:'invalid update: invalid number of rows in section 1. number of rows contained in existing section after update (4) must equal number of rows contained in section before update (0), 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)

how solve exception (or) other example available please suggest me.

please me.

my code:

.m file

#import "expandablelistviewwithservices.h"  @interface expandablelistviewwithservices (){      backgroundpostserviceclass3 * back;     nsmutablearray *arrayforbool,*totallistofarray,*resparray;         nsarray *sectiontitlearray;     uitableview *tablelist;  }  @end  @implementation expandablelistviewwithservices  - (void)viewdidload {     [super viewdidload];          tablelist = [[uitableview alloc] initwithframe:cgrectzero style:uitableviewstylegrouped];     tablelist.translatesautoresizingmaskintoconstraints = no;     tablelist.datasource=self;     tablelist.delegate=self;     tablelist.autoresizingmask = uiviewautoresizingflexibleheight | uiviewautoresizingflexiblewidth;     tablelist.tablefooterview = [[uiview alloc] initwithframe:cgrectzero];     tablelist.tablefooterview = [[uiview alloc] initwithframe:cgrectzero];     [tablelist registerclass:[uitableviewcell class] forcellreuseidentifier:@"cell"];     tablelist.estimatedrowheight = 44.0;     tablelist.rowheight = uitableviewautomaticdimension;     [self.view addsubview:tablelist];      nsdictionary * views = nsdictionaryofvariablebindings(tablelist);      nsarray * horizentalconstraint = [nslayoutconstraint constraintswithvisualformat:@"h:|-0-[tablelist]-0-|" options:0 metrics:nil views:views];      nsarray * verticalconstraint = [nslayoutconstraint constraintswithvisualformat:@"v:|-0-[tablelist]-0-|"options:0 metrics:nil views:views];      [self.view addconstraints:horizentalconstraint];     [self.view addconstraints:verticalconstraint];         [self initialization];  }  -(void)initialization {     arrayforbool=[[nsmutablearray alloc]init];      sectiontitlearray=[[nsarray alloc]initwithobjects:                        @"apple",                        @"strawberry",                        @"grapes",                        @"orange",                        @"banana",                        nil];          nsarray *new0=[[nsarray alloc]initwithobjects:@"apple", @"strawberry",@"grapes",@"orange", nil];      nsarray *new1=[[nsarray alloc]initwithobjects:@"apple1", @"strawberry1",@"grapes1",@"orange1"@"orange1", nil];      nsarray *new2=[[nsarray alloc]initwithobjects:@"apple2", @"strawberry2",@"grapes2",@"orange2", nil];      nsarray *new3=[[nsarray alloc]initwithobjects:@"apple3", @"strawberry3",@"grapes3",@"orange3",@"orange3", nil];      nsarray *new4=[[nsarray alloc]initwithobjects:@"apple4", @"strawberry4",@"grapes4",@"grapes4", nil];      totallistofarray=[[nsmutablearray alloc]init];      [totallistofarray addobject:new0];     [totallistofarray addobject:new1];     [totallistofarray addobject:new2];     [totallistofarray addobject:new3];     [totallistofarray addobject:new4];      (int i=0; i<[sectiontitlearray count]; i++) {          [arrayforbool addobject:[nsnumber numberwithbool:no]];     } }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {      if ([[arrayforbool objectatindex:section] boolvalue]) {                  return [resparray count];      }      else          return 0;  }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *cellidentifier = @"cell2";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      if (cell == nil) {         cell = [[uitableviewcell alloc]initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier];     }      bool manycells  = [[arrayforbool objectatindex:indexpath.section] boolvalue];      //    /********** if section supposed closed *******************/     if(!manycells)     {         cell.backgroundcolor=[uicolor clearcolor];          cell.textlabel.text=@"";     }     /********** if section supposed opened *******************/     else     {         cell.textlabel.text=[nsstring stringwithformat:@"%@",[resparray objectatindex:indexpath.row]];         cell.textlabel.font=[uifont systemfontofsize:15.0f];         cell.backgroundcolor=[uicolor whitecolor];         cell.selectionstyle=uitableviewcellselectionstylenone;      }      cell.textlabel.textcolor=[uicolor blackcolor];      /********** add custom separator cell *******************/     uiview* separatorlineview = [[uiview alloc] initwithframe:cgrectmake(0, 40, tablelist.frame.size.width, 1)];     separatorlineview.backgroundcolor = [uicolor blackcolor];     [cell.contentview addsubview:separatorlineview];      return cell; }  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return [sectiontitlearray count]; }  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      /*************** close section, once data selected ***********************************/     [arrayforbool replaceobjectatindex:indexpath.section withobject:[nsnumber numberwithbool:no]];      [tablelist reloadsections:[nsindexset indexsetwithindex:indexpath.section] withrowanimation:uitableviewrowanimationautomatic]; }  - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     if ([[arrayforbool objectatindex:indexpath.section] boolvalue]) {         return 40;     }     return 0;  }  - (cgfloat)tableview:(uitableview *)tableview heightforheaderinsection:(nsinteger)section {     return 80;  } - (cgfloat)tableview:(uitableview *)tableview heightforfooterinsection:(nsinteger)section {     return 15; } -(uiview *)tableview:(uitableview *)tableview viewforfooterinsection:(nsinteger)section {     uiview *sectionview1=[[uiview alloc]initwithframe:cgrectmake(0, 0, tableview.frame.size.width,40)];     sectionview1.backgroundcolor = [uicolor whitecolor];      return  sectionview1; }  #pragma mark - creating view tableview section //# #e0e0eb place color  - (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section {         uiview *headerview = [[uiview alloc] init];     headerview.backgroundcolor = [uicolor lightgraycolor];     headerview.frame = cgrectmake(0, 0, tableview.frame.size.width, 80);     headerview.tag=section;      uilabel *label1 = [[uilabel alloc] initwithframe:cgrectmake(10, 20, tablelist.frame.size.width, 25)];     label1.text = @"hi";     [headerview addsubview:label1];      uitapgesturerecognizer  *headertapped   = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(sectionheadertapped:)];     [headerview addgesturerecognizer:headertapped];      return headerview;  }  #pragma mark - table header gesture tapped  - (void)sectionheadertapped:(uitapgesturerecognizer *)gesturerecognizer{           nsindexpath *indexpath = [nsindexpath indexpathforrow:0 insection:gesturerecognizer.view.tag];      nslog(@" index ---->>> %ld",(long)indexpath.section);      (int i=0; i<[sectiontitlearray count]; i++){          if (indexpath.section == i) {              bool collapsed  = [[arrayforbool objectatindex:indexpath.section] boolvalue];             (int i=0; i<[sectiontitlearray count]; i++) {                 if (indexpath.section==i) {                     [arrayforbool replaceobjectatindex:i withobject:[nsnumber numberwithbool:!collapsed]];                 }else{                     [arrayforbool replaceobjectatindex:i withobject:[nsnumber numberwithbool:collapsed]];                 }             }             [self selectedoption:(int)indexpath.section];              [tablelist reloadsections:[nsindexset indexsetwithindex:gesturerecognizer.view.tag] withrowanimation:uitableviewrowanimationautomatic];         }     } }  -(nsmutablearray *)selectedoption:(int)myselecteditemdata{      nslog(@"%d",myselecteditemdata);     nsmutablearray *arrayvalue=[[nsmutablearray alloc]init];     resparray=[[nsmutablearray alloc]init];      nslog(@"%@",[totallistofarray objectatindex:myselecteditemdata]);     nslog(@"%d",[[totallistofarray objectatindex:myselecteditemdata] count]);      (int i=0; i< [[totallistofarray objectatindex:myselecteditemdata]count]; i++) {          [arrayvalue addobject:[[totallistofarray objectatindex:myselecteditemdata] objectatindex:i]];         //[arrayvalue addobject:[itemsarray objectatindex:myselecteditemdata]];         nslog(@"array value =======> %@",arrayvalue);         [arrayforbool addobject:[nsnumber numberwithbool:no]];     }      resparray=[arrayvalue mutablecopy];     nslog(@"resparray items =====> %@",resparray);      return arrayvalue; } 

i placing below functions code change have done. see, understand , replace function code.

-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {      nsarray *arraycount = [totallistofarray objectatindex:section];      return [arraycount count]; } - (void)sectionheadertapped:(uitapgesturerecognizer *)gesturerecognizer{        nsindexpath *indexpath = [nsindexpath indexpathforrow:0 insection:gesturerecognizer.view.tag];          nslog(@" index ---->>> %ld",(long)indexpath.section);          (int i=0; i<[sectiontitlearray count]; i++){              if (indexpath.section == i) {                  bool collapsed  = [[arrayforbool objectatindex:indexpath.section] boolvalue];                  (int i=0; i<[sectiontitlearray count]; i++) {                      if (indexpath.section==i) {                          if (collapsed == no) {                              [arrayforbool replaceobjectatindex:i withobject:[nsnumber numberwithbool:yes]];                         }                         else{                               [arrayforbool replaceobjectatindex:i withobject:[nsnumber numberwithbool:no]];                         }                       }else{                          nslog(@"%@",arrayforbool);                          [arrayforbool replaceobjectatindex:i withobject:[nsnumber numberwithbool:no]];                     }                 }                 [self selectedoption:(int)indexpath.section];             }         } } -(nsmutablearray *)selectedoption:(int)myselecteditemdata{      nslog(@"%d",myselecteditemdata);     nsmutablearray *arrayvalue=[[nsmutablearray alloc]init];     resparray=[[nsmutablearray alloc]init];      nslog(@"%@",[totallistofarray objectatindex:myselecteditemdata]);     nslog(@"%lu",(unsigned long)[[totallistofarray objectatindex:myselecteditemdata] count]);      (int i=0; i< [[totallistofarray objectatindex:myselecteditemdata]count]; i++) {          [arrayvalue addobject:[[totallistofarray objectatindex:myselecteditemdata] objectatindex:i]];         nslog(@"array value =======> %@",arrayvalue);     }      resparray=[arrayvalue mutablecopy];      [tablelist reloadsections:[nsindexset indexsetwithindex:myselecteditemdata] withrowanimation:uitableviewrowanimationautomatic];       nslog(@"resparray items =====> %@",resparray);      return arrayvalue; } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -