2015-07-04 42 views
2

所以我在swift中寫了一些東西,它使用了一個帶有四個選項卡的選項卡欄控制器,每個選項卡都可以獨立運行。然而,在主選項卡中,我從數組中選擇最佳值並提供一個鏈接。該數組顯示在第二個選項卡中。如何知道Tab Bar Controller索引是否以編程方式快速更改?

我有一個這樣的代碼:

override func viewWillAppear(animated: Bool) { 
     // some other stuff 

     if dataManager.ideas.count > 0 { 
      lblAllTimeBest.text = "Our all time best with a rating of \(dataManager.ideas[dataManager.allTimeBest].averageRating)% is:" 

      btnAllTimeBest.hidden = false 
      btnAllTimeBest.setTitle(dataManager.ideas[dataManager.allTimeBest].title, forState: UIControlState.Normal) 

     //and some more stuff 
    } 

    @IBAction func btnAllTimeBestTapped(sender: AnyObject) { 
      tabBarController?.selectedIndex = 1 
    } 

我提出了一種基於陣列的索引在第二標籤上的陣列中的項目。如何將索引(我已將其存儲在datamanager中)傳遞到第二個選項卡或者如何知道第二個選項卡上的索引是使用第一個選項卡上的按鈕顯示的?

回答

0

你可以嘗試以下幾種方法(在「recommendedness」順序):

  1. 保持到第二控制器的引用(或檢索特設從標籤欄控制器)和執行的消息第一控制器可以顯式調用
  2. 通過NSNotificationCenter發送NSNotification,聽它在第二控制器的第二控制器
  3. (不推薦)使用某種類型的全局變量的第二控制器可以檢查
相關問題