Swift tab bar view prepareforsegue

In VC1 (view collection), 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 } 

When I get to VC2 (which is a TabBarViewController), I println () chose IndexPassing to see what it returns. He is returning correctly. And then, in VC2, I call this prepareforsegue to go to the actual view controller or the first button on the tab bar:

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

However, when I println () selectedIndexPassingForDisplay in VC3 (PlayerFromRosterViewController), I get zero. Why is the variable passing from the navigation controller of the input panel to VC3, AKA, displayed on the panel of the first panel.

+6
source share
1 answer

Have you checked if prepareForSegue in your TabBarController?

It will never be called because the connection between the UITabBarController controllers and its child views is not a secret storyboard. You should get a link directly to the viewController from the UITabBarController by accessing its collection of viewControllers at the index you need.

 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" 
+19
source

Source: https://habr.com/ru/post/979149/


All Articles