ios - stuck at 3rd level of hierarchal tableview data -
i developing app using storyboard , using 2 uitableview
, 1 label uiviewcontroller
. app take data .plist file. able retrieve data .plsit show in first table , according selected row data shown on second table when click view detail second table 1 array strings can view , can't view others. here sample understating. > aa > aaa , b > bb > bbb.
i have 3 topics in first table i.e. lumber puncture, urinary catheterization , veni puncture. when click on each cell displays me data in second uitableview
according cell. lets suppose showing me following data:
introduction
indication
equipments
etc
now when click introduction of lumber puncture data shows me detail of lumber puncture .plist array data. if click on urinary catheterization introduction on second data cell, shows me first lumber puncture detail. how can solve problem? kindly me detail answers new develop ios apps. thanks
here code first table , passing data second table.
@implementation viewcontroller { nsarray *tabledata; nsarray *components_procedure; } @synthesize tableview1; - (void)viewdidload { [super viewdidload]; // find out path of recipes.plist nsstring *path = [[nsbundle mainbundle] pathforresource:@"recipes" oftype:@"plist"]; // load file content , read data arrays nsdictionary *dict = [[nsdictionary alloc] initwithcontentsoffile:path]; tabledata = [dict objectforkey:@"procedure"]; components_procedure = [dict objectforkey:@"component"]; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [tabledata count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"procedurecell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier]; } cell.textlabel.text = [tabledata objectatindex:indexpath.row]; return cell; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"procedure"]) { nsindexpath *indexpath = [self.tableview1 indexpathforselectedrow]; components *destviewcontroller = segue.destinationviewcontroller; destviewcontroller. componentarray= [components_procedure objectatindex:indexpath.row]; } } @end
second table code , passing detail data uiviewcontrollers uilables
@implementation components { nsarray *detail; } @synthesize tableview2; @synthesize componentarray; - (void)viewdidload { [super viewdidload]; // find out path of recipes.plist nsstring *path = [[nsbundle mainbundle] pathforresource:@"recipes" oftype:@"plist"]; // load file content , read data arrays nsdictionary *dict = [[nsdictionary alloc] initwithcontentsoffile:path]; detail = [dict objectforkey:@"lumberpuncture"]; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [componentarray count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"componentcell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier]; } cell.textlabel.text = [componentarray objectatindex:indexpath.row]; return cell; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"detail"]) { nsindexpath *indexpath = [self.tableview2 indexpathforselectedrow]; detailview *destviewcontroller = segue.destinationviewcontroller; destviewcontroller.headername = [componentarray objectatindex:indexpath.row]; destviewcontroller.contentname = [detail objectatindex:indexpath.row]; } } @end
and detail uiviewcontroller
class
#import "detailview.h" @implementation detailview @synthesize headerlabel; @synthesize headername; @synthesize contentlabel; @synthesize contentname; - (void)viewdidload { [super viewdidload]; // set label text selected recipe headerlabel.text = headername; contentlabel.text = contentname; } @end
you need use both methods, in didselectrowatindexpath should call [self performseguewithidentifier:@"identifier" sender:self];
in same view controller should have prepareforsegue method grab destinationviewcontroller
- (void)tableview:(uitableview *)tableview didselectrowatindexpath (nsindexpath *)indexpath { self.someproperty = [self.somearray objectatindex:indexpath.row]; [self performseguewithidentifier:@"segueid" sender:self]; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { uiviewcontroller *vctopushto = segue.destinationviewcontroller; vctopushto.propertytoset = self.someproperty; }
just add method:
– tableview:didselectrowatindexpath:
typically, use “didselectrowatindexpath” method, invoked after user selects row, handle row selection , add code specify action when row selected.
this , "willselectrowatindexpath" methods used row selection. difference “willselectrowatindexpath” called when specified row selected. make use of method prevent selection of particular cell taking place.
Comments
Post a Comment