ios - How should I use Viewcontrollers -


i'm making app 2 table views. first has bunch of cells lead next table view (which can have different data depending on cell selected). question is, better have bunch of view controllers second menu (1 each cell selection, or have 1 view controller , load different data on it.

there no right or false. however, recommend use different viewcontrollers. if using storyboard, straightforward. connect different cell types appropriate viewcontroller , pass data in -performseguewithidentifier: method. maybe if add details kind of data etc. give more adequate answer.

edit:

in case make more sense work single second tableviewcontroller, input format same , output based on input data. this:

firsttableviewcontroller.h

@interface firsttableviewcontroller.h : uitableviewcontroller  // array containing nsarrays contain nsstrings @property (nonatomic, strong) nsarray *textarrays;  @end 

firsttableviewcontroller.m

@implementation firsttableviewcontroller  @synthesize textarrays;  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {      return self.textarrays.count; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *identifier = @"your identifier";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:identifier forindexpath:indexpath];     if(cell == nil)     {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier];     }      nsarray *textarray = self.textarrays[indexpath.row];     if (textarray != nil && [textarray iskindofclass:[nsarray class]]) {         // configure cell     }      return cell; }  - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     uitableviewcell *cell = (uitableviewcell *)sender;     nsindexpath *indexpath = [self.tableview indexpathforcell:cell];     secondtableviewcontroller *controller = [segue destinationviewcontroller].     controller.textarray = self.textarrays[indexpath.row]; }  @end 

secondtableviewcontroller.h

@interface secondtableviewcontroller.h : uitableviewcontroller  // array containing nsstrings @property (nonatomic, strong) nsarray *textarray;  @end 

secondtableviewcontroller.m

@implementation secondtableviewcontroller  @synthesize textarray;  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {      return self.textarray.count; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *identifier = @"your identifier";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:identifier forindexpath:indexpath];     if(cell == nil)     {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier];     }      nsstring *text = self.textarray[indexpath.row];     if (text != nil && [text iskindofclass:[nsstring class]]) {         // configure cell, e.g. cell.textlabel.text = text;     }      return cell; }  @end 

remember there several ways achieve something. way , not have yours. however, hope helps.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -