gpt4 book ai didi

ios - Swift 标签栏 View prepareforsegue

转载 作者:搜寻专家 更新时间:2023-10-30 21:48:51 26 4
gpt4 key购买 nike

在 VC1( Collection View )中,这是我的 prepareforsegue 代码:

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 来访问实际的 View Controller ,或者标签栏中的第一个按钮:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var segue = segue.destinationViewController as PlayerFromRosterViewController
segue.selectedIndexPassingForDisplay = 1
}

但是,当我在 VC3 (PlayerFromRosterViewController) 中 println() selectedIndexPassingForDisplay 时,我得到了 nil。为什么变量不从选项卡栏导航 Controller 传递到 VC3,也就是第一个选项卡栏按钮 View 。

最佳答案

您是否检查过 TabBarController 中的 prepareForSegue 是否被调用过?

它永远不会被调用,因为 UITabBarController 和它的 subview Controller 之间的连接不是 Storyboard转场。您应该通过访问位于所需索引处的 viewControllers 集合,直接从 UITabBarController 获取对 viewController 的引用。

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"

关于ios - Swift 标签栏 View prepareforsegue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27307903/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com