i have search at https://stackoverflow.com/search?q=UITableView+dataSource+must+return+a+cell+from+tableView%3AcellForRowAtIndexPath ,but i know i need to check if the cell is nil,but my cell is custom,and i am not use xib,i am use storyboard.i am also choice the class CustomPlaceTableViewCell at storyboard.as https://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 the place info
Place *place = [self.placeDataController objectInPlaceListAtIndex:indexPath.row];
//set the cell with 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 the view for the selected state
}
@end
when i run my app ,it give me :
2012-07-02 17:16:26.675 MyAura[2595:707] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:’
first i used :
cause me no data in the table,or give me the mistake,so i used:
all is OK