我的自定义 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-Method和 Apple Documentation of UITableViewCell
要解决未知类属性的其他问题:您的 myCustomCell
是什么类型?在界面生成器中,您必须分配正确的类型,并且您的 myCustomCell
也必须是正确的类型。
关于ios - 自定义 UITableViewCell 图像在滚动之前不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15235625/