Gab*_*urt 0 ios uicollectionview uicollectionviewcell swift
我正在设置一个项目,UICollectionView其中显示带有标签的图像.我创造了ViewController和CellViewController它一样,就像它应该的那样.
在CellViewController代码中如下:
class CellController: UICollectionViewCell {
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var label: UILabel!
}
Run Code Online (Sandbox Code Playgroud)
但是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
}
Run Code Online (Sandbox Code Playgroud)
最奇怪的是,我有一个从GitHub下载的项目,它与我的基本相同,而且工作正常.
提前致谢!
你的问题是:UICollectionViewCell.虽然您将单元格转换为CellController类型UICollectionViewCell,但它没有图像属性.删除或替换它将CellController解决您的问题.
let cell = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController
Run Code Online (Sandbox Code Playgroud)
我还会考虑将您的图片视图重命名为imageView.这条线cell.image.image看起来不对劲!
| 归档时间: |
|
| 查看次数: |
1332 次 |
| 最近记录: |