gpt4 book ai didi

objective-c - 将 UIImageView 添加到自定义 UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 22:46:37 25 4
gpt4 key购买 nike

我似乎无法将此 imageview 添加到我的自定义 uitableviewcell 类中,我无法弄清楚。这是我的代码:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
[self layoutCell];
}
return self;
}

- (void)layoutCell
{
self.videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 310, 120)];
[self.videoImageView setImage:[UIImage imageNamed:@"myImage.jpg"]];
[self.contentView addSubview:self.imageView];
}

在调试器中,我注意到一旦我将 ImageView 添加为内容 View 的 subview ,如果有帮助,框架就会重新分配到 (0,0,0,0)。我真的不知道发生了什么。如果有人有任何建议,那就太好了。我还尝试将 imageview 直接添加到单元格的 View 本身,但无济于事。 (而且我很确定那是错误的)。

谢谢!

最佳答案

你不应该在单元格的 init 方法中设置你的图像。您需要将其分开。

关于objective-c - 将 UIImageView 添加到自定义 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13079255/

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