objective c - TableView on UIViewController with array information -
hi trying use tableview on uiviewcontroler on .h put code:
@interface secondviewcontroller : uiviewcontroller <uitableviewdelegate, uitableviewdatasource> { iboutlet uitableview *mytableview; } @property (nonatomic, retain) iboutlet uitableview *mytableview;
and on .m:
i modify code says response_array undeclared , mytablevview not found on object type uitableviewcell
@synthesize mytableview; - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [_responsearray count]; } - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1; } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] init]; } nsstring *cellvalue = [_responsearray objectatindex:indexpath.row]; [cell.textlabel settext:cellvalue]; return cell; }
here response_array
nsarray* response_array = [json objectforkey:@"avenidas"];
problem: response_array undeclared
in @interface
file create property declares nsarray
@property (retain, nonatomic) nsarray * responsearray;
in @implementation
file @synthesize
property
@synthesize responsearray = _responsearray;
(optional)
in -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath
you can use tableview parameter access tableview instead of mytableview property.
example:
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; }
problem: mytablevview not found on object type uitableviewcell
cell.mytableview = cellvalue;
you trying access tableview within cell? uitableviewcell has default label called textlabel.
so should follows (unless have custom label):
[cell.textlabel settext:cellvalue];
Comments
Post a Comment