swift – didSelectItemAt IndexPath that does not perform segue (but is called)

I have made a request to take the navigationController to a new viewController when an element has been selected in my UICollectionView. The code is executed but the action is not running. However, didSelectItemAt was called, since I verified it by requesting the color changes when it was selected (executed). Any ideas?

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

leave layout = UICollectionViewFlowLayout ()
let controller = ChatLogController (collectionViewLayout: layout)
controller.match = messages?[indexPath.item].match
navigationController? .pushViewController (driver, animated: true)


let cell: UICollectionViewCell = collectionView.cellForItem (at: indexPath)!
cell.backgroundColor = UIColor.magenta
}