我遇到问题时我快速选择和取消选择行在我的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
感谢您的答案。我看了一下,但我认为它与我的有点不同。他总是无,但我的,如果我慢慢做,没有问题... –