I read a lot of questions / answers in the stack overflow community about switching between different ViewControllers but I couldn't find the correct answer for my specific problem.
I'm using a NavigationViewController to "connect" all my different viewControllers (ViewController / TableViewController / CollectionViewController)
I have got some classes which aren't depending on a ViewController class. For example to to calculate anything in my "calculate" class.
I'm searching for an easy solution, to switch between all my ViewControllers. And I would like to decide in my "calculate" class e.g. to go one step back in my Navigation ViewController.
In the moment I use this:
Example to switch between two different ViewControllers:
let sb = UIStoryboard(name: "Main", bundle: nil) let vc = sb.instantiateViewControllerWithIdentifier("StartPage") as! StartPageView self.presentViewController(vc, animated: true, completion: nil)
PROBLEM: This example only works in a ViewController class and the navigation bar disappears.
Example to go one step back in my NavigationViewController:
self.navigationController?.popViewControllerAnimated(true)
PROBLEM: This example only works in a ViewController class.
EDIT 1:
I found a nice solution to call all my viewControllers with this part of code:
let switchViewController = self.navigationController?.viewControllers[1] as! ScanTableView
self.navigationController?.popToViewController(switchViewController, animated: true)
How can I call this code in a non ViewController class?
Push the new view controller onto your existing navigation stack, rather than presenting it modally: