gpt4 book ai didi

ios - 自定义 UITableViewCell 图像直到滚动才显示

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:15:29 24 4
gpt4 key购买 nike

我的自定义 UITableViewCell 图像出现错误,直到滚动 UITableView 才显示。它不会发生在所有单元格上,只有下一个单元格打开或最近一个单元格关闭(例如,如果你看到底部的一半单元格,你就无法看到图像,直到你将它一直滚动到 View 中)

所以我决定,也许我需要做得更好,将我的 UIImages 关联到正确的自定义单元格。

我创建了一个名为“firstImageView”的 UIImageView,然后我进入我的界面构建器并将其与正确的 UIImageView 相关联。

然后在 tableview:cellForRowAtIndexPath: 里面,我试着这样设置

myCustomCell.firstImageView.image = [UIImage imageNamed:@"SMILE.png"];

但是我得到这个错误

Property 'firstImageView' not found on object of type 'UITableViewCell *'

任何帮助将不胜感激

最佳答案

为了解决即将出现的图像的错误,这是我的答案:当您像这样获得 UITableViewCell

MyCustomCell *myCustomCell = [self.tableView dequeueReusableCellWithIdentifier:@"myCustomCellIdentifier"];

您可以实现-(void)prepareForReuse 方法来覆盖UITableViewCell。否则,也可以在单元格出队后在 -(UITableViewCell *)tableView:cellForRowAtIndexPath: 方法中设置自定义内容。

您可以在这里获得更多信息: How to use prepareForUse-MethodApple Documentation of UITableViewCell

要解决未知类属性的另一个问题:您的 myCustomCell 是什么类型?在界面生成器中,您必须分配正确的类型,并且您的 myCustomCell 也必须是正确的类型。

关于ios - 自定义 UITableViewCell 图像直到滚动才显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15235625/

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