我在视图控制器中有一个UITableView。表视图使用名为UserFavoritesCell的自定义单元格。当引用代码这个小区,我得到以下警告:与自定义UITableViewCell不兼容的指针类型警告
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?这种方法实际上会重新创建或从队列中调用单元格,以检索数据中已存在的属性,我猜测? – Astri