ios - 如何重置 Root View Controller

标签 ios swift

是否可以重置 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/

相关文章:

ios - 转换为 swift 3.0 时,UIButton 上 'dismiss()' 的使用不明确

ios - NSManagedObject 保存在核心数据中但属性错误

iphone - 如何在 UIToolBar 中添加条形按钮

ios - 缩放图像 : how can the accelerate be the slowest method?

swift - 台风:从 Storyboard OS X 注入(inject) Controller

ios - "Cannot invoke ' CGPointMake ' with an argument list of type ' ((), CGFloat) '"在 Swift 中收到

ios - Collection View 单元格的多项选择

ios - 解析主播放列表文件后获取单独的视频和音频 url

iphone - iOS:录制语音编码的音频格式,用于网络传输

ios - 如何在 NSURL 中使用非英文字符串?