I have a table. In her custom cell. In each cell there is an ImageView for avatars. Avatar is loaded from the Internet. To upload avatars to this view I use the following code:

cell.avatarIMG.layer.cornerRadius = cell.avatarIMG.frame.height / 2 cell.avatarIMG.clipsToBounds = true let imgURL: NSURL = NSURL(string: post.useravatar!)! let imgData: NSData = NSData(contentsOfURL: imgURL)! cell.avatarIMG.image = UIImage(data: imgData) 

When the screen with the table loads, I get the data, then I reload the table and the data is displayed on the screen. All the rules, but first avatars without pictures. But it is worth scrolling down, then all the rules. And if you go back to the beginning there, too, all the rules, avatars all work and there are pictures. By the method of typing, I found out that if I remove the line from the code:

 cell.avatarIMG.clipsToBounds = true 

Everything is working fine. But with this row, the pictures appear only after the cell is reused.

What is most interesting, in the seventh version of xcode this problem was not. It appeared only after upgrading to version 8.

UPD: while writing a question, in parallel, google, that the problem is in the bug of the eighth xcode. When I request the height of the imageview frame, 1000.0 is returned to me, as a result, the wrong radius is calculated, and this results in a display problem. And after the cell is reused, the size is already correct, which is why the radius becomes correct and the image is displayed.

But then how to get the right height of the ImageView?

    1 answer 1

    I tried to reproduce the problem, but without success. I do exactly as you do, and everything works correctly for me (avatars with pictures are displayed immediately, and not after re-use). I have XCode 8.1. Try it and you upgrade to the latest version - perhaps Apple has fixed this in it.

    • After upgrading to version 8 I had so much nerves shook myself with various glitches and conversions, which I’m afraid to update next)) - cheerful_weasel
    • You can install the second XCode in parallel with the first one; nothing terrible will happen. Anyway, sooner or later you will have to upgrade :-) - BrottyS
    • I did not know about this. I'll have to try. Thank you) - cheerful_weasel