2016-09-07 58 views
0

我正在尝试为我的iOS应用程序实现3D快速操作。 我已经设法添加快速操作,并希望在故事板中打开一个viewcontroller。使用UITabbarController和UINavigationController从故事板调用视图

我的根控制器是一个UITabbarController。在这里面我有一个UINavigationController。

我已经按照这个tutorial

然后我想打开的的appdelegate搜索视图中,我试图做这样的教程。但我只看到一个黑屏。

func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) { 
    if shortcutItem.type == "com.traning.addStuff" { 
     let sb = UIStoryboard(name: "Main", bundle: nil) 
     let searchVC = sb.instantiateViewControllerWithIdentifier("Search") as! SearchView 
     let root = UIApplication.sharedApplication().keyWindow?.rootViewController 

     root?.presentViewController(searchVC, animated: false, completion: {() -> Void in 
      completionHandler(true) 
     }) 


    } 
} 

我的ViewController是我的UINavigationController

[UITab]第三视图 - 控制 - > [UINav] - > [UINav] - > [UINav]

我试图初始化根作为UITabbarController查看,但我如何访问或调用我的视图为UINavigationController?

有什么建议吗?

谢谢!

编辑:

我已经添加的图像来说明我的故事板(这只是一个例子) 我有一个的UITabBarController - >的UINavigationController - >的firstView - > SecondView

enter image description here

随着我想要调用SecondView的3D快速操作。

+0

在呈现之前,尝试根是否尝试根?.definesPresentationContext = true。希望有帮助:) –

+0

@LucianoAlmeida嘿谢谢你,但它仍然无法正常工作。我收到这个日志输出。警告:试图在上呈现,其视图不在窗口层次结构中! – we7ee

+0

既然你有这个日志,你可以试试这种方式:let root = UIApplication.sharedApplication().keyWindow?.rootViewController。改为visibleViewController。希望工程:) –

回答

0

对于所有谁拥有我发现这里的解决方案相同的问题: http://blog.opendatalab.de/hack/2015/10/25/3d-touch-with-tabbarcontroller-and-navigationcontroller

因此,这里是我用来调用secondView代码:

if let tabController = self.window?.rootViewController as? UITabBarController { 
       tabController.selectedIndex = 1 

       let navController = tabController.selectedViewController as? UINavigationController 
       navController?.popToRootViewControllerAnimated(false) 

       let firstView = navController?.viewControllers[0] 
       firstView?.performSegueWithIdentifier("second", sender: nil)     
      } 

的tabController.selectedIndex取决于在您想要执行segue的UITabBarController中的视图项目上。我的情况是它是UITabBarController的第二项。

我希望这会有所帮助。

相关问题