ios – Swift标签栏查看prepareforsegue

前端之家收集整理的这篇文章主要介绍了ios – Swift标签栏查看prepareforsegue前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在VC1(集合视图)中,这是我的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)时,我printInn()selectedIndexPassing以查看返回的内容.它正确返回.然后,在VC2中,我将此prepareforsegue称为实际视图控制器,或标签栏中的第一个按钮:

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

但是,当我在VC3(PlayerFromRosterViewController)中printInn()selectedIndexPassingForDisplay时,我得到了nil.为什么变量没有从Tab Bar导航控制器传递到VC3,AKA是第一个标签栏按钮视图.

解决方法

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

它永远不会被调用,因为UITabBarController与其子视图控制器之间的连接不是故事板segue.您应该通过在所需索引处访问其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相关文章