问题描述
在VC1(集合视图)中,这是我的prepareforsegue代码:
In VC1 (collection view) this is my prepareforsegue code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let segue = segue.destinationViewController as TabBarViewController
var selectedIndex = self.collectionView.indexPathForCell(sender as UICollectionViewCell)
segue.selectedIndexPassing = selectedIndex?.row
}
当我到达VC2时(这是TabBarViewController),我println()selectedIndexPassing看看返回什么。它正确返回。然后,在VC2中,我将此prepareforsegue称为实际视图控制器,或标签栏中的第一个按钮:
When I get to VC2 (which is TabBarViewController), I println() selectedIndexPassing to see what returns. It returns correctly. And then, in VC2, I call this prepareforsegue to get to the actual view controller, or the first button in the tab bar:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var segue = segue.destinationViewController as PlayerFromRosterViewController
segue.selectedIndexPassingForDisplay = 1
}
然而,当我在VC3(PlayerFromRosterViewController)中println() selectedIndexPassingForDisplay
时,我得到零。为什么变量没有从Tab Bar导航控制器传递到VC3,AKA是第一个标签栏按钮视图。
However, when I println() the selectedIndexPassingForDisplay
in VC3 (PlayerFromRosterViewController) I get nil. Why isn't the variable passing from the Tab Bar navigation controller to VC3, AKA the first tab bar button view.
推荐答案
您是否检查过TabBarController中的 prepareForSegue
是否被调用?
Have you checked whether the prepareForSegue
in your TabBarController ever gets called?
由于 UITabBarController
与其子视图控制器之间的连接不是故事板segue,因此永远不会被调用。您应该通过在所需索引处访问 viewControllers
集合,从 UITabBarController
直接获取对viewController的引用。 / p>
It would never be called since the connection between a UITabBarController
and its children view controllers isn't a storyboard segue. You should get a reference directly to the viewController from the UITabBarController
by accessing its viewControllers
collection at the index you want.
var tabBarController = segue.destination as UITabBarController
var destinationViewController = tabBarController.viewControllers[0] as YourViewController // or whatever tab index you're trying to access
destination.property = "some value"
这篇关于Swift标签栏视图prepareforsegue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!