4

I have a UICollectionView, and when selecting an item didDeselectItemAt not get triggered, but when selecting an other item, the first will get triggered. Why?

This is have method is implemented:

override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {

    let userSetting = userSettings[(indexPath as NSIndexPath).row]
    selectedUserSettingRecordName = userSetting.id
    containerViewController!.performSegue(withIdentifier: "message", sender:self)

}

There is no view above the collectionView which could interfere.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
János
  • 32,867
  • 38
  • 193
  • 353
  • 3
    didSelect vs did**De**select? – Larme Oct 06 '16 at 09:56
  • 1
    Possible duplicate of [didSelectRowAtIndexPath returns wrong IndexPath](http://stackoverflow.com/questions/4118993/didselectrowatindexpath-returns-wrong-indexpath) This question is on `UITableView` and not `UICollectionView`, but the system/reason is the same. – Larme Oct 06 '16 at 11:34
  • It one of everyone's favorite mistakes: to mix uр `didDeselectItemAt` and `didSelectItemAt`. – kelin Sep 21 '19 at 06:19

1 Answers1

8

is not

didDeselectItemAt - is called in second time, if you select the any item after that it will call

override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {

it is

didSelectItemAt - is called in first time, if you select the any item it will call

 override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143