2017-08-25 8 views
2

コレクションビューセルの境界線の色を選択または選択解除するにはこのコードを使用しますが、境界線の色は選択しますが境界線の色は選択しないでください。 私は非常に多くのコードを使用しますが、それは情報コレクションビューセルの境界線の色Swiftで選択解除3

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 

} 
+0

あなたの 'didDeselectItemAtIndexPath'関数は' private'ですか? –

+0

'private func collectionView(collectionView:UICollectionView、didDeselectItemAtIndexPath indexPath:IndexPath)'このメソッドはSwift 3のバージョンではないので呼び出されません。 – Larme

+1

[didSelectRowAtIndexPathが動作していない、Swift 3](https://stackoverflow.com/questions/40491818/didselectrowatindexpath-not-working-swift-3)の重複の可能性あり – Larme

答えて

1
func collectionView(_collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: IndexPath) { 
    let cell = collectionView.cellForItemAtIndexPath(indexPath) as! DateCell 

    cell.layer.borderWidth = 2.0 
    cell.layer.borderColor = UIColor.gray.cgColor 
} 
func collectionView(_collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: IndexPath) { 
    let cell = collectionView.cellForItemAtIndexPath(indexPath) as! DateCell 

    cell.layer.borderWidth = 2.0 
    cell.layer.borderColor = UIColor.gray.cgColor 
} 

Try This One 
よう didDeselectItemAt方法から開始で privateキーワードを削除
2

を共有worked.pleaseていなかった私はそれが良い働いて、あなたのコードを使用しますが、単に

func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { 
     let cell = collectionView.cellForItem(at: indexPath) 
     cell?.layer.borderWidth = 2 
     cell?.layer.borderColor = UIColor.gray.cgColor 
    } 
+0

ありがとう、はい私はやったと働いて –

関連する問題