iphone - UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath -
i have search @ https://stackoverflow.com/search?q=uitableview+datasource+must+return+a+cell+from+tableview%3acellforrowatindexpath ,but know need check if cell nil,but cell custom,and not use xib,i use storyboard.i choice class customplacetableviewcell @ storyboard.as http://i.stack.imgur.com/g0rro.png
code:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { customplacetableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; //if ([cell iskindofclass:[customplacetableviewcell class]]) { cell = (customplacetableviewcell *)cell; } //retrieve place info place *place = [self.placedatacontroller objectinplacelistatindex:indexpath.row]; //set cell place info if (place.name) { cell.namelabel.text =place.name; } else { cell.namelabel.text = @"portaura"; } if (place.distance) { cell.distancelabel.text = place.distance; } else { cell.distancelabel.text = @"portaura"; } return cell; } customplacetableviewcell.m @interface customplacetableviewcell : uitableviewcell{ uilabel *namelabel; uilabel *distancelabel; uilabel *addresslabel; } @property (nonatomic) iboutlet uilabel *namelabel; @property (nonatomic) iboutlet uilabel *distancelabel; @property (nonatomic) iboutlet uilabel *addresslabel; @end @implementation customplacetableviewcell @synthesize distancelabel,namelabel,addresslabel; - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { // initialization code } return self; } - (void)setselected:(bool)selected animated:(bool)animated { [super setselected:selected animated:animated]; // configure view selected state } @end
when run app ,it give me :
2012-07-02 17:16:26.675 myaura[2595:707] *** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'uitableview datasource must return cell tableview:cellforrowatindexpath:'
i think miss return cell in tableview:cellforrowatindexpath try this
return cell;
ans check or use nslog(@"description = %@",[cell description]);
if [cell description]
null change it
customplacetableviewcell *cell = (customplacetableviewcell*) [tableview dequeuereusablecellwithidentifier:cellidentifier];
Comments
Post a Comment