iphone - Error when passing data between views -


possible duplicate:
how pass data detail view after being selected in table view?

i'm using plist (array of dictionaries) populate tableview. now, when cell pressed, want pass reprecented dictionary detail view segue. it's working fill tableview, how send same value detail view? try:

#import "winesviewcontroller.h" #import "wineobject.h" #import "winecell.h" #import "winesdetailviewcontroller.h" @interface winesviewcontroller () @end @implementation winesviewcontroller - (id)initwithstyle:(uitableviewstyle)style { self = [super initwithstyle:style]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; } - (void)viewdidunload { [super viewdidunload]; } - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation { return (interfaceorientation == uiinterfaceorientationportrait); } #pragma mark - table view data source - (void)viewwillappear:(bool)animated { wine = [[wineobject alloc] initwithlibraryname:@"wine"]; self.title = @"vinene"; [self.tableview deselectrowatindexpath:[self.tableview indexpathforselectedrow] animated:yes]; } - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // return number of sections. return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // return number of rows in section. return [wine librarycount]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"winecell"; winecell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; // configure cell... cell.namelabel.text = [[wine libraryitematindex:indexpath.row] valueforkey:@"name"]; cell.districtlabel.text = [[wine libraryitematindex:indexpath.row] valueforkey:@"district"]; cell.countrylabel.text = [[wine libraryitematindex:indexpath.row] valueforkey:@"country"]; cell.bottleimageview.image = [uiimage imagenamed:[[wine libraryitematindex:indexpath.row] valueforkey:@"image"]]; cell.flagimageview.image = [uiimage imagenamed:[[wine libraryitematindex:indexpath.row] valueforkey:@"flag"]]; cell.fyldeimageview.image = [uiimage imagenamed:[[wine libraryitematindex:indexpath.row] valueforkey:@"fylde"]]; cell.friskhetimageview.image = [uiimage imagenamed:[[wine libraryitematindex:indexpath.row] valueforkey:@"friskhet"]]; cell.garvesyreimageview.image = [uiimage imagenamed:[[wine libraryitematindex:indexpath.row] valueforkey:@"garvesyre"]]; return cell; } #pragma mark - table view delegate - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([[segue identifier] isequaltostring:@"detailsegue"]) { nsindexpath *selectedrowindex = [self.tableview indexpathforselectedrow]; winesdetailviewcontroller *winesdetailviewcontroller = [segue destinationviewcontroller]; //here comes error line: winesdetailviewcontroller.winedetailname = [wine objectatindex:indexpath.row] valueforkey:@"name"]; } } 

i 1 error for:

winesdetailviewcontroller.winedetailname = [wine objectatindex:indexpath.row] valueforkey:@"name"]; 

use of undeclaired identifier: indexpath. did mean nsindexpath? think i've missed important here..

instead of indexpath.row (which doesn't exist in function in tableview:cellforrowatindexpath: function passed argument) use selectedrowindex this:

 winesdetailviewcontroller.winedetailname = [wine objectatindex:selectedrowindex.row] valueforkey:@"name"]; 

or, better yet, change detail view controller accept whole dictionary, pass dictionary, , let set its' own values:

 winesdetailviewcontroller.winedetail = [wine objectatindex:selectedrowindex.row]; 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -