Wednesday, 15 January 2014

ios - Using an “IF” statement for popping to two possible View Controllers -



ios - Using an “IF” statement for popping to two possible View Controllers -

currently have segue hooked uitableview pops next uitableview in navigation stack.

what need though instead, set if statement based on text in uitableview cell, to decide which of 2 possible uiviewcontrollers pop to.

so viewcontroller2 needs able pop either":

- viewcontroller1

or

- forwards viewcontroller3

based on text in uitableview cell populated json.

can help me out that? post code needed. thanks!

current viewcontroller:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"standardcell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; spring *spring = [springs objectatindex:indexpath.section]; leaf *leaf = [spring.leafs objectatindex:indexpath.row]; cell.textlabel.text = leaf.shortname; homecoming cell; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { // new view controller using [segue destinationviewcontroller]. // pass selected object new view controller. if ([segue.identifier isequaltostring:@"themes"]) { uitableviewcell *cell = (uitableviewcell*)sender; nsindexpath *indexpath = [self.tableview indexpathforcell:cell]; // reference destination view controller mrtviewcontroller *tvc = (mrtviewcontroller *)[segue destinationviewcontroller]; } }

update added code per @troops still not sure how pop vc3

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview cellforrowatindexpath:indexpath]; nsstring *stringtocheck = @"aaa"; if([cell.textlabel.text isequaltostring:stringtocheck]) { //pop vc1 [self.navigationcontroller poptoviewcontroller:[[self.navigationcontroller viewcontrollers]objectatindex:0] animated:yes]; } else { //pop vc3, not sure set here // pass info tvc.spring = [springs objectatindex:indexpath.section]; tvc.leaf = [tvc.spring.leafs objectatindex:indexpath.row]; tvc.buttonnumber = _buttonnumber; } }

you check cell's textlabel's string: if want utilize segues , not tableview's delegate method of: didselectrowatindexpath: that's why based reply off initial question/code looks like.

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview cellforrowatindexpath:indexpath]; nsstring *stringtocheck = @"aaa"; if ([cell.textlabel.text isequaltostring:stringtocheck]) { // pop vc1 [self.navigationcontroller poptorootviewcontrolleranimated:yes]; } else { // force vc3 mrtviewcontroller3 *tvc = [self.storyboard instantiateviewcontrollerwithidentifier:@"yourid"]; tvc.spring = [springs objectatindex:indexpath.section]; tvc.leaf = [tvc.spring.leafs objectatindex:indexpath.row]; tvc.buttonnumber = _buttonnumber; [self.navigationcontroller pushviewcontroller:tvc animated:yes]; } }

ios objective-c uitableview segue

No comments:

Post a Comment