我只是想不起来了,请帮助我了解这里的情况:
因此,我拥有要在UICollecionView中查看的图像资源。我有一组图像名称和文件名,因此在collectionView:cellForItemAtIndexPath:函数内部
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as ImageCell
let currentPhoto = photos[indexPath.row]
let currentImage = UIImage(named: currentPhoto.filename)
cell.imageC?.image = currentImage
println("collectionView:cellForItemAtIndexPath:\(indexPath.row)")
println(currentPhoto.filename)
println("currentImage \(currentImage!.imageAsset)")
println("cell.image \(cell.imageC?.image)")
return cell
imageC在
class ImageCell: UICollectionViewCell {
@IBOutlet weak var imageC: UIImageView!
}
所以我看到currentImage正确获取图像。Println给了我这个:
currentImage <UIImageAsset: 0x7fead1e55790>
但是,cell.imageC?.image为零!为什么?我对可选参数感到困惑,实际上并没有想到将变量和常量进行包装/拆包的想法,但是在这里,我所做的一切与TableView教程中的操作完全相同。请给我一些线索-我陷入泥泞
我在viewDidLoad()中注释掉的OMG
self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
而且有效!我不确定为什么,但是作为一种临时解决方案,它对我来说效果很好。
奇怪的是,如果您尝试创建新的UIViewCollectionController类,则此行代码是默认viewDidLoad()方法的一部分
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句