gpt4 book ai didi

ios - 在 Swift 中从登录 Storyboard 迁移到主 Storyboard,无需发出警告

转载 作者:行者123 更新时间:2023-11-30 13:43:46 24 4
gpt4 key购买 nike

在用户登录我的应用程序后,我尝试将 View Controller 从登录 Storyboard更改为我的主 Storyboard,此操作成功,但我在控制台中收到以下警告:

2016-02-05 01:57:59.553 Commu[4749:160489] Warning: Attempt to present <UITabBarController: 0x7f93285b9d90> on <Commu.LoginViewController:     0x7f9328494e80> whose view is not in the window hierarchy!

我的登录 View Controller 中的代码如下:

dispatch_async(dispatch_get_main_queue(), { () -> Void in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("MainMenu")
self.presentViewController(vc, animated: true, completion: nil)
})

是否有更好的方法在 Storyboard之间移动以避免出现此警告消息?

最佳答案

用户登录后,不再需要登录层次结构。

成功登录后,您需要更改主窗口的 Root View Controller ,即appDelegate窗口的rootViewContoller。

同样,当用户注销时再次更改窗口的rootViewContoller。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("MainMenu")


let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = vc

您还可以在层次结构中包含 UINavigationController,以推送和弹出其他 viewController。

关于ios - 在 Swift 中从登录 Storyboard 迁移到主 Storyboard,无需发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35224201/

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