0

My code worked well so far. I do not see what I could change to make it bug like that. When I want to return the user to the home page, it works, but a few seconds after the previous ViewController reappears on the screen.

I've tried to change "as! HomeViewController" with "as UIViewController" or as NavigationViewController but it keeps going to the previous ViewController.

    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let balanceViewController = storyBoard.instantiateViewController(withIdentifier: "home") as! HomeViewController
    self.present(balanceViewController, animated: true, completion: nil)
itinous
  • 1
  • 3
  • Btw, you don't have to downcast instantiated controller to your custom subclass or `UIViewController` either if you just need to present it. – Robert Dresler Feb 18 '19 at 14:59

1 Answers1

0

When I want to return the user to the home page...

You should use UINavigationController.popToViewController(_:animated:) to return to a UIViewController:

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let balanceViewController = storyBoard.instantiateViewController(withIdentifier: "home") as! HomeViewController
self.navigationController?.popToViewController(balanceViewController, animated: true)
KeroppiMomo
  • 564
  • 6
  • 18
  • It doesn't work... Plus, the problem is the same in AppDelegate with self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "home") as! UIViewController – itinous Feb 18 '19 at 15:27