大家好我有一个视图组织的应用程序,如下图:
我的应用程序必须在用户打开附件时打开视图B(从图中)(我还有另一个问题Open specific view when user opens an attachment,我找到了这个问题的答案)。我已经这样做了我的问题是,当我打开View B时,标签栏不存在。
有没有办法在我打开View B时看到根视图中的tabbar?
更新 以下是我用来从 AppDelegate.swift文件打开视图的代码:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("AddComment") as! AddCommentViewController
window?.rootViewController = vc
}
答案 0 :(得分:2)
刚看到你的最新帖子。为了实现这一点,必须遵循以下规则:
window?.rootViewController
是一个UITabBarController indexOfNavigationViewControllerInTabBar
处的视图控制器是UINavigationViewController。如果是,那么请执行:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
let indexOfNavigationViewControllerInTabBar = 0 // Set yourself
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("AddComment") as! AddCommentViewController
let tabBarController = window?.rootViewController as! UITabBarController
let navigationController = tabBarController.viewControllers![indexOfNavigationViewControllerInTabBar] as! UINavigationController
navigationController.setViewControllers([vc], animated: true)
tabBarController.selectedIndex = indexOfNavigationViewControllerInTabBar
}