ios - Passing NSString from View Controller to TableViewController -
can please advise on how pass array of nsstrings viewcontroller tableviewcontroller. have tried using prepareforsegue in rootviewcontroller
-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { tableviewcontroller *transferviewcontroller = segue.destinationviewcontroller; nslog(@"segue %@", segue.identifier); if ([segue.identifier isequaltostring:@"segueaffiliation"]) { // segue affiliation happened transferviewcontroller.titletext = @"friendly"; } else if ([segue.identifier isequaltostring:@"seguecategory"]) { // segue category happened } else if ([segue.identifier isequaltostring:@"seguefunction1"]) { // segue function1 happened } else if ([segue.identifier isequaltostring:@"seguefunction2"]) { // segue function2 happened } else if ([segue.identifier isequaltostring:@"seguefunction3"]) { // segue function3 happened }
and not sure on how pass data, far have in tableviewcontroller
@interface tableviewcontroller () @end @implementation tableviewcontroller { nsarray *_tabledata; } - (id)initwithstyle:(uitableviewstyle)style { self = [super initwithstyle:style]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; // initialize table data self.celltitle.text = self.titletext; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - table view data source - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // return number of sections. return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // return number of rows in section. return [_tabledata count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; // configure cell... return cell; }
you have declare array _tabledata in header file :
@property (strong, nonatomic) nsarray *_tabledata;
and in .m file :
@synthesize _tabledata;
currently _tabledata private.
Comments
Post a Comment