Why doesn't my .pushViewController work from didSelectItemAt in swift

97 Views Asked by At

I am trying to push a viewController when i user selects a item from a list through the didSelectItemAt function but when ever a user selects the item nothing happens.

This is how my didSelectItemAt function looks so far:

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    print(stores[indexPath.row].storeName)
    let myStore = UserStoreVC(collectionViewLayout: UICollectionViewFlowLayout())
    myStore.store = stores[indexPath.row]
    navigationController?.pushViewController(myStore, animated: true)
}

This is how i have set up my UserStoreVC class:

class UserStoreVC: UICollectionViewController, UICollectionViewDelegateFlowLayout {}

When a user selects the item the function does get called as the store name is printed correctly through the print function but nothing is being presented and i am not sure why not.

Have i done something wrong as this is how i have pushed other viewControllers in the same app and it works correctly

how do i make it work?

when i add a breakpoint to this line i get this:

enter image description here

DiscoverCollection Collection View:

let collectionView: DiscoverCollection = {
    let layout = UICollectionViewFlowLayout()
    layout.scrollDirection = .horizontal
    let view = DiscoverCollection(collectionViewLayout: layout)
    return view
}()
1

There are 1 best solutions below

6
Kudos On

Step 1: Look here step by step for adding NavigationController for your ViewController : enter image description here

Step 2: Click to add NavigationController for your VC. enter image description here

Step 3: Finally you have navigationController. enter image description here