UICollectionViewCell stays black when used with SDWebImage

I want to get images from Instagram API and then show them in iOS iOS application UICollectionViewusing SDWebImage. But after loading the image into the cells, the cells remain black.

Here's the code inside cellForItemAtIndexPath::

let photo = self.photosArray[indexPath.row] as! AnyObject
let photoUrlString = photo.valueForKeyPath("images.standard_resolution.url")! as! String
print(photoUrlString) // properly show the URL 
let imageView = UIImageView()
imageView.sd_setImageWithURL(NSURL(string: photoUrlString), placeholderImage: nil)
print(cell.frame) // confirmed that the frame is not 0
cell.contentView.addSubview(imageView)

However, the cell remains black on the screen.

I also test it by calling cell.contentView.backgroundColor = UIColor.redColor(), then it is wrapped on a red screen. But the image still did not appear on the screen.

How can I display an image in a cell?

UPDATE

I tried adding UILabelto my cell using the same one addSubview:, the label was correctly displayed. I am not sure why this is not so with the image ...

+4
source share
1

, UIImageView . :

let imageView = UIImageView(frame: cell.contentView.frame.bounds)
+1

Source: https://habr.com/ru/post/1599774/


All Articles