UITableView dataSource必须从tableView:cellForRowAtIndexPath返回一个单元格 [英] UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath
问题描述
我在 https://stackoverflow.com进行了搜索/ search?q = UITableView + dataSource + must + return + a + cell + from + tableView%3AcellForRowAtIndexPath ,但我知道我需要检查单元格是否为零,但我的单元格是自定义的,我不是使用xib,我使用storyboard.i我也选择了storyboard.as上的类CustomPlaceTableViewCell http:/ /i.stack.imgur.com/g0rRO.png
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 http://i.stack.imgur.com/g0rRO.png
代码:
- (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] ***由于未捕获的异常'NSInternalInconsistencyException'终止应用程序,原因:'UITableView dataSource必须从tableView返回一个单元格:cellForRowAtIndexPath:'
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:'
推荐答案
我首先使用:
PlaceMasterViewController *placeController = [[PlaceMasterViewController alloc]init];
[self.navigationController pushViewController:placeController animated:YES];
导致我表中没有数据,或者给我错误,所以我用过:
cause me no data in the table,or give me the mistake,so i used:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle: nil];
PlaceMasterViewController *placeController = (PlaceMasterViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"peoplemastViewControl"];
[self.navigationController pushViewController:placeController animated:YES];
一切正常
这篇关于UITableView dataSource必须从tableView:cellForRowAtIndexPath返回一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!