本文介绍了如何重置根视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以重置根视图控制器?重置是指将其重置为初始状态,以便再次调用 viewDidLoad
.我正在使用 UITabBarController
,当我注销时,希望卸载以前加载的所有选项卡.
Is it possible to reset the root view controller? With reset I mean resetting it to its initial state so viewDidLoad
will be called again. I'm using a UITabBarController
and when I logout I want all the tabs previously loaded to be unloaded.
推荐答案
您可以通过在注销操作时将TabBarController的实例设置为 rootViewController 来实现.
You can do this by setting the instance of TabBarController to rootViewController on logout action.
快捷键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()
目标C:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabBarController = [storyBoard instantiateViewControllerWithIdentifier:@"TabBarController"];
[[[UIApplication sharedApplication] keyWindow] setRootViewController:tabBarController];
[[[UIApplication sharedApplication] keyWindow] makeKeyAndVisible];
这篇关于如何重置根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!