Swift ios didSelectItemAt not called until second click

Viewed 446

My didSelectItemAt function is not being executed until I click on a second cell, but it is executing with the data obtained from the first cell clicked. Otherwise everything is working as expected. Help?

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

    let id = boardArray[indexPath.row]
    let boardId = id.title
    let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let boardViewController = storyBoard.instantiateViewController(withIdentifier: "BoardViewController") as! BoardViewController
    boardViewController.name = boardId
    self.present(boardViewController, animated: true, completion: nil)
}

So after I click a second cell, it will display the 'BoardViewController' with the first cell's boardId & such.

Thanks, Jewell

1 Answers

You use didDeselectItemAt instead of

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

use

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { }
Related