I have CollectionViewController, when I am trying to click on cell and navigate to respective ViewControllers its not working.how can I solve this issue.
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell:AddOptionCollectionViewCell = collectionView.cellForItem(at: indexPath) as! AddOptionCollectionViewCell
if (cell.name.text == "CONTRAST"){
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "ContrastViewController") as! ContrastViewController
self.navigationController?.pushViewController(newViewController, animated: true)
}
I think this problem is due to nil value of navigation stack for your CollectionViewController class. So, first of all go to storyboard and select CollectionViewController class and embed NavigationController into it. After this try and run it will work.
All the best.
In my case, I mistakenly added the MainViewController
to the window.rootViewController
instead of adding it to the UINavigationController
and then using the navigation as rootViewController
.
at SceneDelegate.swift
, it should be:
let navigationController = UINavigationController()
navigationController.pushViewController(MainRouter.createModule(using: navigationController), animated: false)
window.rootViewController = navigationController
window.makeKeyAndVisible()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With