I have created a CollectionView and I want to open a ViewController with specific details depending on which row was clicked.(I'm not using a storyboard this is all done programatically).
I've looked at the documentation and I am trying to use the override function didSelectItemAt
and navigationController?.pushViewController()
but nothing seems to happen. No error or anything? See my Code:
I've also tried supplying the layout to the viewcontroller but no luck. It is clearly accepting the click function of each row because it prints out to the log fine:
Any help to what i've missed here would be appreciated.
First, make sure in your TabBarController
, the controller is initialized as navigationController
func viewDidLoad() {
let vc1 = UINavigationController(rootViewController: YourController())
viewControllers = [vc1, vc2]
}
before you put it into viewControllers
array, so that you could call navigationController?.pushViewController()
in vc1
Another thing: Make sure you give a flow layout when initializing CollectionViewController
before push, like so:
let layout = UICollectionViewFlowLayout()
let detailVC = PlaceDetailController(collectionViewLayout: layout)
detailVC.place = ... // Pass value here
navigationController?.pushViewController(detailVC, animated: true)