2016-11-12 17 views
1

私はタブ付きアプリケーションを作成しました。最初のタブ(ViewController + TableView)には、DBから取得した結果が表示されます。別のViewControllerを開くボタンがあり、ユーザは結果をフィルタリングできます(「city」など)。ViewControllerからTabBarControllerの最初のタブへの接続

今、どのようにして最初のタブ付きページに戻ることができますか?私はDBにクエリを行うためにパラメータを渡す必要があるので。このページと最初のViewControllerの間にセグを作成すると、タブ付きメニューは表示されません。

ありがとうございます。

+1

戻るには巻き戻し用セグを使用する必要があります – Paulw11

答えて

0

あなたが達成しようとしているのは、あるタブから別のタブにデータを渡すことです。

は「今、どのように私はセグエでまずタブ付きページに戻ることができますか?私はDBへのクエリを実行するためにパラメータを渡す必要がありますので。

を実際に、あなたドン「トンではなく、あなたが次の操作を行うことができ、データを渡すためにセグエを実行する必要があります。

// 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

私はそれを意味していませんでした。私は巻き戻しセグを使用していました。 :) ありがとうございました –

関連する問題