【发布时间】:2017-12-12 20:39:31
【问题描述】:
我面临的问题是,当我想以编程方式呈现视图时,我的应用程序崩溃/显示空白的黑色视图。
当用户点击通知时会打开 vc。 我有一个标签栏、一个导航控制器和一个可以从标签栏中的第一个 vc 访问的视图。
当我想推送 vc 时,我的应用程序崩溃了,但是当我删除要推送到 vc (ChatVC)中的 viewDidLoad() 中的所有内容时,我的应用程序显示 vc 但为空且黑色。 我的应用委托推送代码。 这与 chatvc 无关,我尝试了我拥有的每个视图控制器,但它同时崩溃了。
let chatVc = AllChatsViewController()
if let tabbarControler = window?.rootViewController as? MainTabBarController {
tabbarControler.selectedIndex = 0
//tabbarControler.presentedViewController?.dismiss(animated: true, completion: nil)
if let homeNav = tabbarControler.viewControllers?.first as? UINavigationController {
homeNav.pushViewController(chatVc, animated: true)
print(followerId)
}
}
}
更新
if let chatPartnerId = userInfo["chatPartnerId"] {
let storyboard = UIStoryboard(name:"Chat", bundle: Bundle.main)
guard let chatVC = storyboard.instantiateViewController(withIdentifier: "MessageViewController") as? MessageViewController else {return}
chatVC.userId = chatPartnerId as! String
if let tabbarControler = window?.rootViewController as? MainTabBarController {
tabbarControler.selectedIndex = 0
tabbarControler.presentedViewController?.dismiss(animated: true, completion: nil)
if let homeNav = tabbarControler.viewControllers?.first as? UINavigationController {
homeNav.pushViewController(chatVC, animated: true)
}
}
它现在按预期推送到 ViewController 但不会调用 viewDidLoad 或任何其他函数,任何想法?
【问题讨论】:
-
我也试过了,设置self.window?.rootViewController = tabBarController self.window?.makeKeyAndVisible()时崩溃了