ios - UITableView with Multiple Data Arrays -


i have app, in have 7 different uitableviewcontrollers. 7 linked through tabbarcontroller. looking way have single custom class used throughout 7 uitableviewcontrollers. have 7 different arrays hold specific number of objects. need know how to:

  • change number of rows in tableview, depending on array i'm using data source.
  • change array being used data source based on viewcontroller user looking @ (can done?)
  • change contents of cell, based on array being used data source.

i'm familiar using uitableview single data source, don't know how approach multiple data sources.

thanks!

• change number of rows in tableview, depending on array i'm using data source.

you can accomplish conditions in tableview delegates

- (nsinteger)tableview:tableview numberofrowsinsection:section 

inside delegate need identify datasource particular tableview.

check table if 1 being refreshed so:

- (nsinteger)tableview:tableview numberofrowsinsection:section {     if (tableview == self.firsttableview)         return self.firsttabledatasource.count;      if (tableview == self.secondtableview)         return self.secondtabledatasource.count;      //and on.. } 

• change array being used data source based on viewcontroller user looking @ (can done?)

figuring array using particular table you. can use segement control, buttons, table, it's you.

but important part [tableview reloaddata]; @ target table (table active) , again table delegates triggered , doing filtering inside delegates..

while can check if viewcontroller visible by:

if ([self/*viewcontroller*/ isviewloaded] && self/*viewcontroller*/.view.window) {     //visible }  

which discussed here

• change contents of cell, based on array being used data source.

this 1 not clear. content/values of subviews of cell like: cell.textlabel, cell.detailtextlabel , cell.imageview?

or cell.contentview basically, want change of cell?

if content/values again have determine which, (using customcell):

assuming have datasource looks like:

{     data_source = (             {                 text_label = test0;                 detail_label = "this text";                 image_name = "your_image0.png";             },             {                 text_label = test1;                 detail_label = "this text";                 image_name = "your_image1.png";             }         ) } 

then in delegate cellforrowatindexpath it'll like:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellid = @"tableid";      self.customcell = [tableview dequeuereusablecellwithidentifier:cellid];      if (!self.customcell)         self.customcell = [[yourcustomcell alloc] initwithstyle:(uitableviewcellstyle) reuseidentifier:cellid];      static nsstring *datasource = @"data_source";     static nsstring *textlabel = @"text_label";     static nsstring *detaillabel = @"detail_label";     static nsstring *imagename = @"image_name";      if (tableview == self.firsttableview)     {         self.customcell.textlabel.text = [self.firstdatasource valueforkey:datasource][indexpath.row][textlabel];         self.customcell.detailtextlabel.text = [self.firstdatasource valueforkey:datasource][indexpath.row][detaillabel];         self.customcell.imageview.image = [uiimage imagenamed:[self.firstdatasource valueforkey:datasource][indexpath.row][imagename]];     }      if (tableview == self.secondtableview)     {         self.customcell.textlabel.text = [self.seconddatasource valueforkey:datasource][indexpath.row][textlabel];         self.customcell.detailtextlabel.text = [self.seconddatasource valueforkey:datasource][indexpath.row][detaillabel];         self.customcell.imageview.image = [uiimage imagenamed:[self.seconddatasource valueforkey:datasource][indexpath.row][imagename]];     }     // , on... } 

to check other methods, check apples documentation ,i hope useful , others well.. happy coding.. :)


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -