0

If a storyboard contains a view in a navigation controller that segues to another view controller already embedded in a tab controller how can a variable be passed from the initial view to the first view in a tab controller?

Specifically, I am looking to pass a variable using a basic performSegueWithIdentifier approach. By connecting the first view controller (embedded in a navigation controller) to the tab controller, I am unable to pass the data. However, if the connection is made directly between the first view controller and the destination view controller, the destination is no longer embedded in the tab.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "internalItemDetail" {
        let destination = segue.destinationViewController as InternalInventoryDetail
        let index = itemTable.indexPathForSelectedRow()!
        destination.fmRecordId = sectionedItemArray[index.section][index.row]["fmRecordId"] as String!
    }
}

To be clear, the goal is to pass a variable from a navigation controller into another view which is embedded in a tab controller while the UI would be showing a tab controller inside a navigation controller.

Michael Voccola
  • 1,827
  • 6
  • 20
  • 46

1 Answers1

0

The UIStoryBoardSegue has a destinationViewController property that will give you the target view controller- in your case a UITabBarController (if I'm reading your question correctly). You'll have to cast it to a UITabBarController and from there you can access its subviews. (Code in objective c but should be easy to convert, I've just never used swift)

UITabBarController *tabControl = (UITabBarController *)segue.destinationViewController;
MyViewController *mv = (MyViewController *)tabControl.viewControllers[0];// whatever index you want
Bourne
  • 336
  • 3
  • 4