ios - 自定义 UITableViewCell 图像在滚动之前不会显示

标签 ios uitableview uiimageview

我的自定义 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/

相关文章:

ios - swift 4 : Cannot assign value of type '[X]' to type '[VC.X]'

php - 如何使用 Cordova 和 PHP 后端(在 FireBase 上)实现 Apple Sign In

iphone - 当我上下滚动时,UITableView 仅显示来自 JSON 的数据

ios - UIImageView 中的渐变/阴影,如 Flipboard

ios - 加载 Viewcontroller 的新部分

ios - 如何在 Swift 中隐藏 UITableView 部分?

ios - Swift - 自动排序 UITableView

ios - 保存和加载 UIImageView

iphone - 触摸时旋转 View

ios - Swift Cocoa 按钮未到位