2016-11-12 62 views
1

我創建了一個選項卡式應用程序。在第一個選項卡(ViewController + TableView)中,它顯示從DB獲取的結果。我有一個打開另一個ViewController的按鈕,用戶可以在其中篩選結果(例如,針對「城市」)。從ViewController繼續到TabBarController的第一個選項卡

現在,我怎樣才能返回到第一個帶有segue的標籤頁?因爲我需要傳遞參數才能對數據庫執行查詢。如果我在這個頁面和第一個ViewController之間創建一個segue,它不會顯示標籤菜單。

謝謝你們。

+1

你需要使用一個unwind segue回去 – Paulw11

回答

0

我假設你想要實現的是將數據從一個標籤傳遞到另一個標籤。

「現在,我怎樣才能返回到第一標籤頁用賽格瑞?因爲我需要傳遞,以做一個查詢到數據庫的參數。

其實,你不「T必須執行SEGUE來傳遞數據,而不是你能做到以下幾點:

// somewhere in your code when you need to pass data to another tab viewController: 
if let tabBarController = tabBarController { 
    let secondTabViewController = tabBarController.viewControllers![1] as! SecondViewController 
    // let's assume that you want to pass a string 
    secondTabViewController.str = "my str!!" 
} 

SecondViewController:

class SecondViewController: UIViewController { 
    // here is the string that had been passed from the first tab viewController: 
    var str:String? 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // note that the output is: "Optional("my str!!")" 
     print(str) 

     // do optional binding: 
     if let unwrappedStr = str { 
      // output is: "my str!!" 
      print(unwrappedStr) 
     } 
    } 
} 

我希望它有幫助。

+0

這不是我的意思..我用了Unwind segue,它的工作原理! :) 謝謝 –

相關問題