gpt4 book ai didi

iphone - UITableView dataSource 必须从 tableView :cellForRowAtIndexPath 返回一个单元格

转载 作者:行者123 更新时间:2023-12-03 19:13:48 24 4
gpt4 key购买 nike

我在 https://stackoverflow.com/search?q=UITableView+dataSource+must+return+a+cell+from+tableView%3AcellForRowAtIndexPath 进行搜索,但我知道我需要检查单元格是否为零,但我的单元格是自定义的,而且我不使用xib,我使用storyboard。我还选择storyboard.as /image/g0rRO.png中的CustomPlaceTableViewCell类

代码:

- (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

当我运行我的应用程序时,它给我:

2012-07-02 17:16:26.675 MyAura[2595:707] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView dataSource 必须从 tableView:cellForRowAtIndexPath 返回一个单元格:”

最佳答案

我认为您错过了 tableView 中的返回单元格:cellForRowAtIndexPath试试这个

return cell; 

检查或使用此NSLog(@"description = %@",[cell description]);

如果[单元格描述]为空,则更改它

CustomPlaceTableViewCell *cell = (CustomPlaceTableViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

关于iphone - UITableView dataSource 必须从 tableView :cellForRowAtIndexPath 返回一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11290746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com