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