Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在UICollectionView中取消选择项目时,应用程序崩溃_Swift_Ios8_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Swift 在UICollectionView中取消选择项目时,应用程序崩溃

Swift 在UICollectionView中取消选择项目时,应用程序崩溃,swift,ios8,uicollectionview,uicollectionviewcell,Swift,Ios8,Uicollectionview,Uicollectionviewcell,我正在开发UICollectionView。当用户选择一个图像时,我将其分配给集合视图单元格,当用户选择其他单元格时,我将更改该图像,如下面的代码所示 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){ let selectedCell : CollectionCellForAlertView = collectionView.ce

我正在开发UICollectionView。当用户选择一个图像时,我将其分配给集合视图单元格,当用户选择其他单元格时,我将更改该图像,如下面的代码所示

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){

    let selectedCell : CollectionCellForAlertView = collectionView.cellForItemAtIndexPath(indexPath) as! CollectionCellForAlertView
    println("cell selected")
    selectedCell.imageView.image = UIImage(named: "someImage.png")

}

func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath){
    println("deselected")
    let deselectedCell : CollectionCellForAlertView = collectionView.cellForItemAtIndexPath(indexPath) as! CollectionCellForAlertView
    deselectedCell.imageView.image = UIImage(named: "someOtherImage.png")

}

有时它工作正常,但有时会崩溃,因为“取消EdCell”的值为零。有谁能告诉我如何解决这个问题。

我想这可能对你有用。我在我的应用程序中测试了它,它成功了

     let deselectedCell = collectionView.cellForItemAtIndexPath(indexPath) as CollectionCellForAlertView
        deselectedCell.imageView.image = UIImage(named: "someOtherImage.png")

不,它不起作用。。正如我所说的,有时它会在其他时间崩溃时正常工作。我的收藏视图中大约有15项。当我向下滚动并继续选择和取消选择时,它会在某个时候崩溃。你能把你的项目上传到github吗,这样我就可以看一看了。