[英]how to release memory,object,viewcontroller when you pop to root 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.