gpt4 book ai didi

ios - 自定义单元格设置 ImageView

转载 作者:行者123 更新时间:2023-11-29 10:42:34 24 4
gpt4 key购买 nike

我制作了自定义 UITableViewCell 并将 UIImageView 添加到单元格。
然后,当我构建时,应用程序异常终止并显示以下日志消息。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NewsCell setImageView:]: unrecognized selector sent to instance 0x109139f80'

我有这个代码。

ViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[NewsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
cell.imageView.image = [UIImage imageNamed:@"abcde.jpg"];
break;
}
}
return cell;
}

新闻单元格

@interface NewsCell : UITableViewCell

@property (nonatomic, strong) UIImageView* imageView;
@property (nonatomic, strong) UILabel* titleLabel;

@end

NewsCell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 44, 40)];
[self.contentView addSubview:self.imageView];
self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 5, 200, 25)];
self.titleLabel.font = [UIFont systemFontOfSize:24];
[self.contentView addSubview:self.titleLabel];
}
return self;
}

如何修复它以将自定义单元格反射(reflect)到 tableView?

最佳答案

我可能是错的,但我认为 imageView 属性已经在 UITableViewCell 上实现,并且它是一个只读属性。在子类上重新实现它可能会产生冲突。

尝试更改您的 imageView 属性的名称,如果可行请告诉我。

关于ios - 自定义单元格设置 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23812537/

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