我遇到問題時我快速選擇和取消選擇行在我的collectionView
中。 我有一張地圖,上面有一個水平的collectionView
,我選擇我想看的東西。在collectionview中選擇和取消選擇行時出錯
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let selectedCell:UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)!
selectedCell.contentView.backgroundColor = UIColor(red: 102/256, green: 255/256, blue: 255/256, alpha: 0.66)
switch indexPath.row {
case 0:
query0()
break
case 1:
query1()
break
case 2:
query2()
break
case 3:
query3()
break
default:
break
}
}
和取消選擇的代碼是:
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let cellToDeselect:UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)!
cellToDeselect.contentView.backgroundColor = UIColor.clearColor()
}
錯誤我得到的是這樣的:
fatal error: unexpectedly found nil while unwrapping an Optional value
,當我試圖慢慢選擇單元格,我沒有得到錯誤 但是,如果我迅速做它崩潰
我評論的取消功能,我沒有得到任何錯誤(我用細胞的快速變化檢查)
看看這個unswear http://stackoverflow.com/a/22861956/4525866 – salabaha
感謝您的答案。我看了一下,但我認爲它與我的有點不同。他總是無,但我的,如果我慢慢做,沒有問題... –