ios - Why I can't pass data using segue -
i have plist contains key , value... let say:
key: alpha_male_body_language value: alpha male body language key: building_attraction value: building attraction key: fifteen_lessons value: fifteen lessons key: how_can_it_have_gone_wrong value: how can have gone wrong
here implementation of tableview:
#import "booktitleviewcontroller.h" #import "booklessonviewcontroller.h" @interface booktitleviewcontroller () @end @implementation booktitleviewcontroller{ nsdictionary *booktitles; } @synthesize tableview; @synthesize booktitles; - (void)viewdidload { [super viewdidload]; self.booktitles = [nsdictionary dictionarywithcontentsoffile:[[nsbundle mainbundle] pathforresource:@"book" oftype:@"plist"]]; } - (void)viewdidunload { [super viewdidunload]; // release retained subviews of main view. self.booktitles = nil; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation { return (interfaceorientation != uiinterfaceorientationportraitupsidedown); } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [self.booktitles count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"recipecell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier]; } nsstring *value = [[self.booktitles allvalues] objectatindex:indexpath.row]; //cell.textlabel.text = [recipes objectatindex:indexpath.row]; cell.textlabel.text = value; return cell; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"showbooklesson"]) { nsindexpath *indexpath = [self.tableview indexpathforselectedrow]; booklessonviewcontroller *destviewcontroller = segue.destinationviewcontroller; destviewcontroller.booktitlekey = [[self.booktitles allkeys] objectatindex:indexpath.row]; destviewcontroller.booktitlevalue = [[self.booktitles allvalues] objectatindex:indexpath.row]; //destviewcontroller.recipename = [recipes objectatindex:indexpath.row]; } } @end
i have 2 problems using code above:
the list not shown in order after reading plist. example, title "how can have gone wrong" shown on first list, knowing fact listed on 4th.
i exception saying:
-[uinavigationcontroller setbooktitlevalue:]: unrecognized selector sent instance 0x894c230
this referring line:
destviewcontroller.booktitlekey = [[self.booktitles allkeys] objectatindex:indexpath.row]; destviewcontroller.booktitlevalue = [[self.booktitles allvalues] objectatindex:indexpath.row];
(inside prepareforsegue function).
please helps me solve problem. thank , appreciate it!
more detail on possible solution problem 2:
- add
uistoryboardsegue+mmnavigationcontroller.h
project, found in this github repo - import header file in view controller's implementation file
- change 1 line in implementation of
prepareforsegue:sender:
so:
booklessonviewcontroller *destviewcontroller = segue.topleveldestinationviewcontroller;
explanation: if storyboard segue points points destination view controller wrapped in uinavigationcontroller
, segue's destinationviewcontroller
value navigation controller object. code referenced here handle checking whether destinationviewcontroller
instance of uinavigationcontroller
class, , if so, return topviewcontroller
instead. implemented on uistoryboardsegue
class; categories way add methods or properties existing class extend functionality without needing use inheritance, etc.
Comments
Post a Comment