gpt4 book ai didi

ios - 如何重置 Root View Controller

转载 作者:搜寻专家 更新时间:2023-10-31 22:05:06 24 4
gpt4 key购买 nike

是否可以重置 Root View Controller ?重置是指将其重置为初始状态,以便再次调用 viewDidLoad。我正在使用 UITabBarController,当我注销时,我希望卸载之前加载的所有选项卡。

最佳答案

您可以通过在注销操作时将 TabBarController 的实例设置为 rootViewController 来做到这一点。

swift 3:

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyBoard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
UIApplication.shared.keyWindow?.rootViewController = tabBarController
UIApplication.shared.keyWindow?.makeKeyAndVisible()

objective-c :

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabBarController = [storyBoard instantiateViewControllerWithIdentifier:@"TabBarController"];
[[[UIApplication sharedApplication] keyWindow] setRootViewController:tabBarController];
[[[UIApplication sharedApplication] keyWindow] makeKeyAndVisible];

关于ios - 如何重置 Root View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45303292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com