2016-09-07 60 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的第二項。

我希望這會有所幫助。

相關問題