[英]How do I know if Tab Bar Controller index was changed programatically in swift?
So I am writing a little something in swift that uses a tab bar controller with four tabs, each are fully functioning on their own. 因此,我在快速编写一些东西,它使用带有四个选项卡的选项卡栏控制器,每个选项卡都可以独立运行。 However in the main tab I select the best value from an array and provide a link to it.
但是,在主选项卡中,我从数组中选择最佳值并提供指向它的链接。 The array is presented in the second tab.
该阵列显示在第二个选项卡中。
I have a code like this: 我有这样的代码:
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
}
I present the items of the array on the second tab based on array index. 我根据数组索引在第二个选项卡上显示数组的项目。 How do I pass the index (I store it in datamanager already) to the second tab OR how do I know on the second tab that it was presented using the button on the first one?
如何将索引(已经将其存储在datamanager中)传递给第二个选项卡,或者如何在第二个选项卡上知道使用第一个按钮显示的索引?
You can try these options (in order of "recommendedness"): 您可以尝试以下选项(按“推荐”顺序):
NSNotification
via NSNotificationCenter
and listen to it in the second controller NSNotification
经由NSNotificationCenter
和收听它在第二控制器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.