我正在尝试在 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/