使用核心数据致命错误填充数组

时间:2015-07-05 06:53:28

标签: ios iphone swift core-data photos

我正在使用核心数据填充数组。所以我拍了一张照片,它保存了,并且应该在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的集合单元格。

1 个答案:

答案 0 :(得分:1)

您的代码不会打开标记为1的集合单元格.viewWithTag()返回标记为1的单元格“cell”的子视图。因此,如果该单元格不包含带标记值的子视图1,返回一个nil,所以错误。