【发布时间】:2019-07-23 18:18:40
【问题描述】:
如果应用程序在前台运行,我正在尝试检查特定的 VC。我的根视图控制器类是SWRevealViewController。之后我有一个TabBarController,在它下面有NavigationController 和ViewController。
我的继承人是,
SWRevealViewController --> TabBar 控制器 --> 导航控制器 --> MessageVC --> ChatVC
如果应用程序在 ChatVC 上运行,我想检查应用程序委托,如果在前台运行,我已经尝试过此代码,
let tabBar:UITabBarController = self.window?.rootViewController as! UITabBarController
let navInTab:UINavigationController = tabBar.viewControllers?[1] as! UINavigationController
let storyboard = UIStoryboard(name: "Dashboard", bundle: nil)
let destinationViewController = storyboard.instantiateViewController(withIdentifier: "ChatDetailViewController") as? ChatDetailViewController
if destinationViewController?.restorationIdentifier == "ChatDetailViewController"
{
print("Yes")
}
else
{
print("No")
}
但应用程序因此错误而崩溃,
无法将“SWRevealViewController”(0x100dc4b20) 类型的值转换为“UITabBarController”(0x211b289f0)。
我如何检查应用程序是否在 ChatVC 上?
故事板截图:
【问题讨论】:
-
检查窗口?.visibleViewController
-
你需要签入
SWRevealViewControllerNavigationController,而不是 TabBar NavigationController。 -
我该如何检查? @dahiya_boy
-
我已经设置好了,让 vc = UIStoryboard().loadSWRevealController() appDeleg.window?.rootViewController = vc appDeleg.window?.makeKeyAndVisible() 。在 DidFinish 代表中。 @KrishnaDattShukla