UITableView,单元格中的图像未显示,尽管在 UI View Hierachy 检查器中显示 [英] UITableView, Image in cell isn't showing, despite showing in UI View Hierachy inspector

查看:17
本文介绍了UITableView,单元格中的图像未显示,尽管在 UI View Hierachy 检查器中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use a UITableView with custom UITableViewCells. In the cells I have a UIImageView. I assign an image to that image view from a url from my model. All this have been working fine until now.

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

When the cell is returned in cellForRowAtIndexPath, the image is fetched through a UIImageView extension and assigned to the image property when the async fetch returns.

图像没有显示在 UIImageView 中,尽管之前工作过(这个问题可能是在 Xcode 8 发布后发生的)

The image doesn't show in the UIImageView, dispite having worked before (maybe this problem occured after Xcode 8 was released)

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

What's even more strange, it appear right in the UI View Hierachy Inspector in Xcode.

发生了什么事??

设备截图:

Xcode 中 UI View Hierachy Inspector 的屏幕截图

推荐答案

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

Move your code that changes corner radius from awakeFromNib to layoutSubviews in your cell subclass like the example below. This should fix it.

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

这篇关于UITableView,单元格中的图像未显示,尽管在 UI View Hierachy 检查器中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆