2016-02-09 47 views
0

我在我的應用程序中使用3D觸摸快捷方式時遇到問題。我的應用程序使用選項卡,但我想將用戶重定向到選項卡,然後在按下創建願望列表按鈕時也將其轉換爲另一個選項卡。3D觸摸快捷鍵到選項卡視圖,然後執行segue

Here is a picture of my storyboard.

我使用目前的代碼顯示主視圖控制器,但我想它進入創建願望清單控制器。

我有一個應用程序的委託裏面的把手快捷方式的代碼是在這裏:

func handleShortcut(shortcutItem:UIApplicationShortcutItem) -> Bool { 
      print("Handling shortcut") 

      var succeeded = false 

      if(shortcutItem.type == "com.example.Giftr") { 

       print("- Handling \(shortcutItem.type)") 

       if let tabVC = self.window?.rootViewController as? UITabBarController{ 
       tabVC.selectedIndex = 1 
       //This is where I need to swap to the "createwishlist" view controller. 
} 
+0

因此,此代碼成功地進入正確的選項卡,那麼你的問題是在這之後做一個賽格? –

+0

是的,這是正確的它進入正確的選項卡,但是當我提出視圖控制器的標籤然後消失,並在頂部的導航控件。 – onemillion

+0

你有沒有想過這個想法?我目前有同樣的問題 –

回答

0

爲了解決這個我用一個全局變量來存儲快捷已經採取了的appDelegate裏面像下面。

  GlobalVars.shortcut = 1 
      let tabVC = window?.rootViewController as! UITabBarController 
      print(tabVC.self) 
      tabVC.selectedIndex = 0 

然後,對於將selectedIndex 0的標籤的控制器內部檢查,如果該值是1,並且如果它是然後segued到,我想在落得視圖控制器。如圖所示。

override func viewDidAppear(animated: Bool) {  
     if(GlobalVars.shortcut == 1) 
     { 
      self.performSegueWithIdentifier("shortcut", sender: self) 
      GlobalVars.shortcut = 0 
     } 
    } 

確保您將全局變量設置爲0,否則每次出現視圖時都會調用該變量。

0

這應該能夠到ViewController更改爲需要下課後您成功切換標籤。

let vc = ViewController() //change this to your class name 
self.presentViewController(vc, animated: true, completion: nil) 
+0

這工作,但我希望它有選項卡回到主視圖控制器,所以我想「執行segue」。這是很難解釋,但現在它加載視圖沒有導航或標籤,但我想加載與導航欄在頂部,並選中選項卡。 – onemillion

相關問題