I have a UIViewController with a Container View. The container view has a navigation controller with which I can display different scenes within the main view.
Structure:
MainVC
1SubVC (Container View) inside MainVC
2SubVC (ContainerView) inside MainVC
Now my question: Can I execute a function from my MainVC so that the 1SubVC pushes to the 2SubVC?
Something like ->
class MainVC {
1SubVC().doThisPushFunc()
}
Thanks!
2
Answers
Update
For everyone who is looking for a similar solution.
The solution was the NotificationCenter.
Listener für Notification in SubView1 in ViewDidLoad
objc func in SubView1 to execute the notification
Call the notification from MainVC
By saying "push" I’m assuming you’re going to use a UINavigationController and push a view controller onto the navigation stack. The main reason you would use a UINavigationController class is to have helpful functionality like the animation when you’re pushing to a new view controller or if you’re needing a top navigation bar.
If you’re just wanting to go from showing 1SubVC to 2SubVC, then replace the container view.
If you’re wanting to have MainVC notify 1SubVC to make the
navigationController.pushViewController()
call then access an instance of 1SubVC() so you can call the push methode.g. Inside of MainVC