4

I am a rookie in Swift. I have a initial viewController within a navigationController. Inside that is a tableView. When i click on the add button item in the NavigationBar a new viewController is present modaly. Now i click a another button in the presented Vc and the presented Vc is dismiss. The root Vc is present now. But i will show a new root vc. I will set a new root Vc when dismiss the second Vc.

Can i set a new root Vc programmaticly when i dismiss a second vc?

shilovk
  • 11,718
  • 17
  • 75
  • 74
Jurie
  • 117
  • 1
  • 7

1 Answers1

10

Try this out,

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
let navigationController = UINavigationController(rootViewController: newViewController)            
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.window!.rootViewController = navigationController
chinmayan
  • 1,304
  • 14
  • 13