Control another tab bar controller's view to root view by Swift code

611 Views Asked by At

I am new to swift code. I got a question but can't find out the solution for few days and also didn't got the answer from web, too.

I have an app and the root view controller is a UITabBarController. I have two UINavigationControllers controlled by this UITabBarViewController. Each UINavigationController with some UITableViewController and ViewController inside.

My question is that if I press a UIButton in anywhere, I want all UINavigationController go back to root view (the default state when I startup the app). Is it possible to done this by swift code?

Anyone's help would be greatly appreciated. Thank you very much!

1

There are 1 best solutions below

1
On

I think you can reach your rootViewController from anywhere like this

  var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
  let myTabBarView = (appDelegate.window?.rootViewController as? UITabBarViewController)!
  self.presentViewController(myTabBarView, animated: true, completion: nil)