【发布时间】:2013-11-26 23:55:49
【问题描述】:
我在视图控制器中有一个 UITableView。表格视图使用一个名为 UserFavoritesCell 的自定义单元格。在代码中引用此单元格时,我收到以下警告:
Incompatible pointer types initializing UserFavoritesCell with an expression of UITableViewCell.
由于 UserFavoritesCell 是 UITableViewCell 的子类,我不确定为什么会收到此警告。有任何想法吗?谢谢!
标题:
@interface UserFavoriteCell : UITableViewCell
// properties...
@end
实施:
@implementation UserFavoriteCell
@synthesize lblFlow, lblHeight, lblLastUpdate, lblMainTitle, gaugeID;
- (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
在我的视图控制器中,我收到有关 UserFavoriteCell 实例化的警告,如下所示:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UserFavoriteCell *cell = [tableView cellForRowAtIndexPath:indexPath]; // warning
GaugeViewController *gvc = [[GaugeViewController alloc] init];
[gvc setGaugeID:[cell gaugeID]];
[self performSegueWithIdentifier:@"sgDetailFave" sender:self];
}
【问题讨论】:
-
为什么你使用单元格而不是使用实际数据源来获取gaugeID?这个方法实际上会重新创建或从队列中调用单元格,只是为了检索我猜你的数据中已经存在的属性?
标签: ios objective-c uitableview