我试图在UICollectionView
中显示图像。下面的代码负责显示单元格。CollectionView单元格不显示
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
}
我看到的是一个空白视图控制器。当我点击屏幕时,细节VC弹出(如它应该)。看起来好像视图的信息在那里,但只是没有在屏幕上呈现。为了确保图像显示,我需要做些什么改变?
是你的视图控制器的数据源?你的cellForItem会被调用吗? –
如果你的memes.count> 0使用collectionView?.reloadData() –
@JoshHamet在这种情况下,数据源是应用程序委托中的数组,在调用时,项目的单元格被调用 –