簡體   English   中英

連接到導航控制器時如何將ViewController彈出到根目錄

[英]How to pop ViewController to root when connected to navigation controller

我試圖從連接到navigationController的視圖控制器調用popToRootViewController函數。 當我刪除該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)
    }
}

故事板

據我了解,當用戶單擊注銷時,您想彈出到根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)將彈出到當前導航堆棧上的根控制器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM