Rapsefar Rapsefar - 2 months ago 8
Swift Question

UITableView, Image in cell isn't showing, despite showing in UI View Hierachy inspector

I use a

UITableView
with custom
UITableViewCell
s. 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.

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.

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

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

What's going on??

Screenshot from device:

Screenshot from device

Screenshot from UI View Hierachy Inspector in Xcode

enter image description here

Answer

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
    }
Comments