在下面的场景中,我什至无法显示单元格背景(黑色)。
在 Storyboard 中,我有一个容器,其中嵌入了自定义 UICollectionView 和自定义 UICollectionViewCell,并以 ImageView 作为导出。在另一个 View Controller 中,我插入了一个容器,我想要相同的 Collection View 和单元格。
我似乎能够实例化自定义 Collection View 和单元格(都打印到控制台并且不返回 nil)。以下代码打印如下。
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
print("into the collectionView")
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("photoCell" , forIndexPath: indexPath) as! PhotoCollectionViewCell
cell.backgroundColor = UIColor.blackColor()
let myRect = CGRect(x: 0, y: 0, width: 78, height: 78)
cell.frame = myRect
cell.autoresizesSubviews = false
if let imageForCell = images?[indexPath.row]
{
cell.cellImageView.image = imageForCell
print("cell image \(cell.cellImageView.image)")
}
print(cell.cellImageView?.bounds.size)
cell.cellImageView?.layer.borderWidth = 1.0
cell.cellImageView?.layer.borderColor = UIColor.blackColor().CGColor
return cell
}
进入 Collection View
单元格图片可选(, {320, 213})
可选((78.0,78.0))
我已经尝试了所有建议的解决方案,但无法让单元格显示在 Collection View 中。
最佳答案
关于swift - 从 Storyboard (未嵌入)实例化的 Collection View 中未显示单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36154417/