Search code examples
iosswiftxcodestoryboardcollectionview

How to switch/update viewcontroller using one one Viewcontroller?


enter image description here

enter image description here

let's say I have 6 different viewControllers with different contents inside it, and one mainViewController. And MainViewcontroller contains a collectionView iside it, and when one of its cells are selected, I would like to have another stand alone ViewController which handles the update and switch function to the corresponding (6 different Controllers, in this case) viewControllers.. I have implemented the storyBoard showSegue method so far, it is however working , but i think it is not clean and the most right way since storyBoard seagues look a bit messy with this method, Can anyone explain or guide me through this, how to go about it..?


Solution

  • In my opinion you should avoid putting many view controllers in one storyboard. I prefer using the Coordinator pattern. Here is an example: https://www.hackingwithswift.com/articles/71/how-to-use-the-coordinator-pattern-in-ios-apps

    In my projects I use one Storyboard per ViewController and I have a coordinator that I can access from anywhere in the app. It makes your code super flexible. Give it a try...