Reputation: 11961
I am trying to write a piece of code that will pop to the root view controller, then will push another view controller, I have this so far:
self.navigationController?.popToRootViewController(animated: true)
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Posts") as! PostsController
self.navigationController?.pushViewController(viewController, animated: true)
The navigation controller is going to the root view controller, but its not pushing the other view controller, I get this is my console log:
Presenting view controllers on detached view controllers is discouraged
Is what I am trying to do not possible?
Upvotes: 0
Views: 738
Reputation: 2269
Try this -
if let navCont = navigationController {
var controllers = navCont.viewControllers
controllers.removeLast()
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Posts") as! PostsController
controllers.append(viewController)
navCont.setViewControllers(controllers, animated: true)
}
Upvotes: 1