我试图从连接到popToRootViewController
的视图控制器调用navigationController
函数。当我删除该navigationController
时,无法转到我的RootViewController
。但是,如果有连接到的导航控制器(我的情况:TableViewController)ViewController
。 popToRootViewController
将以navigationController
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 2 && indexPath.row == 0 {
Utilities.shared.clearTokens()
navigationController?.popToRootViewController(animated: false)
}
}
答案 0 :(得分:0)
据我了解,当用户单击注销时,您想弹出到根viewController,您应该更改应用程序的根控制器,您可以这样做
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
因为navigationController?.popToRootViewController(animated: false)
将弹出到当前导航堆栈上的根控制器