NSCollectionViewItem을 다시 클릭하여 어떻게 선택을 해제 할 수 있습니까? 다른 항목을 클릭 할NSCollectionViewItem을 클릭하여 선택 해제
func collectionView(collectionView: NSCollectionView, didSelectItemsAtIndexPaths indexPaths: Set<NSIndexPath>) {
print("selected")
guard let indexPath = indexPaths.first else {return}
print("selected 2")
guard let item = collectionView.itemAtIndexPath(indexPath) else {return}
print("selected 3")
(item as! CollectionViewItem).setHighlight(true)
}
func collectionView(collectionView: NSCollectionView, didDeselectItemsAtIndexPaths indexPaths: Set<NSIndexPath>) {
print("deselect")
guard let indexPath = indexPaths.first else {return}
print("deselect 2")
guard let item = collectionView.itemAtIndexPath(indexPath) else {return}
print("deselect 3")
(item as! CollectionViewItem).setHighlight(false)
}
/////////////////////
class CollectionViewItem: NSCollectionViewItem {
func setHighlight(selected: Bool) {
print("high")
view.layer?.borderWidth = selected ? 5.0 : 0.0
view.layer?.backgroundColor = selected ? NSColor.redColor().CGColor : NSColor(calibratedRed: 204.0/255, green: 207.0/255, blue: 1, alpha: 1).CGColor
}
}
이 코드 deslect 있지만 같은 항목이있는 경우 :
이
내가 선택하고 해제를 위해 사용하는 코드입니다. 같은 항목을 클릭하면 사라지고 싶습니다.