【发布时间】:2017-08-25 11:17:54
【问题描述】:
使用此代码选择或取消选择集合视图单元格的边框颜色,但它选择了边框颜色但没有取消选择边框颜色。 我用了这么多代码,但没有用。请分享信息
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
Image2.image = UIImage(named: Images[indexPath.row])
let cell = collectionView.cellForItem(at: indexPath)
cell?.layer.borderWidth = 2
cell?.layer.borderColor = UIColor.green.cgColor
collectionView.allowsMultipleSelection = false
// selectedIndexPath = collectionView.indexPathsForSelectedItems!
}
private func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.layer.borderWidth = 2
cell?.layer.borderColor = UIColor.gray.cgColor
}
【问题讨论】:
-
你的
didDeselectItemAtIndexPath函数是private? -
private func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: IndexPath)不应调用该方法,因为它不是 Swift 3 版本。 -
感谢 Piyush Patel 成功了,我用错了方法
标签: ios swift3 uicollectionview