1

Im trying to call popToRootViewController function from a view controller that is connected to a navigationController. When i removed that navigationController im able to go to my RootViewController. But if there is a navigation controller connected to (My case: TableViewController ) ViewController. the popToRootViewController will end up with the navigationController

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.section == 2 && indexPath.row == 0 {
        Utilities.shared.clearTokens()
        navigationController?.popToRootViewController(animated: false)
    }
}

Storyboard

Vaisakh KP
  • 437
  • 1
  • 5
  • 21

1 Answers1

0

As i understand you want to popup to your root viewController when user click sign out you should cahnge the app root controller you can do it like this

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let newViewController = let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let rootViewController = storyBoard.instantiateViewController(withIdentifier:"your identifier")
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.window!.rootViewController = rootViewController

because navigationController?.popToRootViewController(animated: false) will pop to root controller on your current navigation stack

Ali Adam
  • 191
  • 7