我試圖在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在這種情況下,數據源是應用程序委託中的數組,在調用時,項目的單元格被調用 –