将UIImageView图像设置为非零UIImage导致UIImageView图像为nil

时间:2017-08-01 16:15:08

标签: ios swift uiimageview uiimage

我使用图像填充集合视图单元格,代码如下所示。

 override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MemeCollectionViewCell", for: indexPath) as! MemeCollectionViewCell
    print("Cell is \(String(describing: cell))")
    let meme = memes[(indexPath as NSIndexPath).row]
    print("cell for item at gets called")
    cell.memeImageView?.image = meme.meme
    print("Meme Image \(String(describing: meme.meme))")
    print("Cell Image \(String(describing: cell.memeImageView?.image))")
    // Configure the cell

    return cell
}

在控制台中,我看到以下内容:

Cell is <MemeMe_2_0.MemeCollectionViewCell: 0x7f8c045495b0; baseClass = UICollectionViewCell; frame = (0 0; 136 136); layer = <CALayer: 0x600000234640>>
cellfor item at gets called
Meme Image <UIImage: 0x60000028fcd0> size {414, 736} orientation 0 scale 1.000000
Cell Image nil

我在方法中将imageView.image属性设置为meme.meme(这是一个UIImage),但是当我打印imageView图像的描述时,它被认为是零。为什么会这样呢?

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

0 个答案:

没有答案