swift - UITableView,尽管在 UIView 层次结构检查器中显示,但单元格中的图像未显示

标签 swift xcode uitableview asynchronous

我使用带有自定义 UITableViewCellUITableView。在单元格中,我有一个 UIImageView。我从我的模型的 url 将图像分配给该 ImageView 。到目前为止,所有这些都运行良好。

当在 cellForRowAtIndexPath 中返回单元格时,通过 UIImageView 扩展获取图像并在异步获取返回时分配给 image 属性。

图像在 UIImageView 中不显示,尽管以前工作过(可能是 Xcode 8 发布后出现此问题)

更奇怪的是,它出现在 Xcode 的 UI View Hierachy Inspector 中。

这是怎么回事??

设备截图:

Screenshot from device

Xcode 中 UI View Hierachy Inspector 的屏幕截图

enter image description here

最佳答案

将更改角半径的代码从 awakeFromNib 移动到单元格子类中的 layoutSubviews,如下例所示。这应该可以解决它。

    override func layoutSubviews() {
        super.layoutSubviews()
        self.contentView.layoutIfNeeded()
        imageView.layer.cornerRadius = CGRectGetHeight(imageView.bounds) / 2.0
        imageView.clipsToBounds = true
    }

关于swift - UITableView,尽管在 UIView 层次结构检查器中显示,但单元格中的图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39851548/

相关文章:

iphone - 奇怪的行为-选择行触摸没有响应 UITableViewCell

xcode - 为什么 switch 语句中的 'case' 是负缩进的?

iphone - 安装 IPA 导致错误 "A signed resource has been added, modified, or deleted"

ios - 查看 Controller 加载两次 - 如何修复?

ios - 在 iOS 中,选定的单元格应移动到顶部,而不会影响 UITableView

ios - 来自 xib 中自定义 TableCell 的 PresentViewController

swift - 在闭包内调用闭包

ios - 带有两个自定义单元格的 UITableView 未正确显示

swift - 如何制作水平滚动的 2 行多列 UICollectionView

Xcode 6.1.3 无法更改模拟屏幕尺寸