我正在建立一个带有的项目,该项目UICollectionView
显示带有标签的图像。我创建了ViewController
和CellViewController
,就像它应该做的那样。
在CellViewController
代码中如下所示:
class CellController: UICollectionViewCell {
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var label: UILabel!
}
但是,ViewController
当我设置图像时,它给了我错误。这是代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: UICollectionViewCell = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController
cell.image.image = UIImage(named: "star")
return cell
}
最奇怪的是,我有一个从GitHub下载的项目,该项目与我的项目基本相同,并且运行良好。
提前致谢!
你的问题是:UICollectionViewCell
。尽管您将单元格CellController
强制转换为类型UICollectionViewCell
,但该类型没有image属性。删除它或将其替换CellController
将解决您的问题。
let cell = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController
我也考虑将您的图片视图重命名为imageView
。关于这条线cell.image.image
,有些东西看起来不正确!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句