【发布时间】:2015-07-05 06:53:27
【问题描述】:
我正在用核心数据填充一个数组。所以我拍了一张照片,它保存了,应该在 uiview 中返回我的图像,但得到了这个错误:
致命错误:在展开可选值时意外发现 nil
我在进入视图控制器查看之前拍了照片,但是当我这样做时,它给了我这个错误。
var stores = [Image]()
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as UICollectionViewCell
let store = stores[indexPath.row]
var imageView = cell.viewWithTag(1) as UIImageView
imageView.image = UIImage(data: store.image as NSData)
这段代码应该是解开标签为 1 的集合单元格。
【问题讨论】:
-
你有一个名为
Image的类吗? -
是的,我刚刚解决了这个问题,但致命错误仍然存在。
-
展开错误发生在哪一行?提供该段的代码。
-
@HideShidara 你在使用 Storyboard 吗?我建议您创建一个自定义单元格(
UICollectionViewCell的子类),其中包含需要配置的每个子视图的属性(IBOutlet,如果您使用 xib/storyboard)。
标签: ios iphone swift core-data photos