ios - CollectionView 单元格未显示

标签 ios swift uicollectionview

我正在尝试在 UICollectionView 中显示图像。下面的代码负责显示单元格。

    super.viewWillAppear(animated)
    memes = appDelegate.memes
    collectionView?.reloadData()

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    let space:CGFloat = 3.0
    let dimension = (view.frame.size.width - (2 * space)) / 3.0

    flowLayout.minimumInteritemSpacing = space
    flowLayout.minimumLineSpacing = space
    flowLayout.itemSize = CGSize(width: dimension, height: dimension)
    flowLayout.sectionInset = UIEdgeInsets(top: 1.0, left: 1.0, bottom: 1.0, right: 1.0)
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MemeCollectionViewCell", for: indexPath) as! MemeCollectionViewCell
    let meme = memes[(indexPath as NSIndexPath).row]

    cell.memeImageView?.image = meme.meme
    // Configure the cell

    return cell
}

我所看到的只是一个空白的 View Controller 。当我单击屏幕时,会弹出 VC 的详细信息(应该如此)。看起来 View 的信息在那里,但只是没有在屏幕上呈现。我需要进行哪些更改才能确保显示图像?

最佳答案

您的 collectionview 委托(delegate)未被调用。 你必须写

collectionview.delegate = self collectionview.dataSource = self

如果正在召集代表,请检查 meme.meme 是否有图像。

关于ios - CollectionView 单元格未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45430119/

相关文章:

ios - 调整 UIImage 的大小 - 性能问题

php - 如何快速使用现有的 php/mysql 散列密码

Swift - 网络请求和后台队列

ios - 在 Collection View 中准备 segue

ios - 使用 swift 3 在后台打开 url?

ios - 流式上传文件:显示错误日志“操作无法完成。 (kCFErrorDomainCFNetwork错误303。)”

java - APNS - 无法使用 Java 向 iOS 设备发送通知

iOS 通过 SNS 推送通知

ios - 如何将 UIImages 数组添加到 Collection View

ios - 使用动态大小的单元格限制 UICollectionView 的数量