macosnscollectionview

NSCollectionview didSelectItemsAt not getting called second time


I am developing mac os application where I am using NSCollectionview where at some point I need to get data of particular index where i have implemented didSelectItemsAt delegate method, Now issue is when I click on cell first time it will get executing that didSelectItemsAt and then after I have clicked on another cell it is not executed that method, whenever I reload reload view controller and click on any cell it executed didSelectItemsAt but not for the second time.

Below delegate method which i have implemented.

func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>){

}

Solution

  • Add below line at the end of your logic in the didSelectItemsAt method.

    func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>){
            collectionView.deselectAll(nil)
        }