Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set a new Root viewController in Swift 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?

like image 836
Jurie Avatar asked Jan 03 '23 08:01

Jurie


1 Answers

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
like image 55
chinmayan Avatar answered Mar 05 '23 23:03

chinmayan