0

I currently have a storyboard that has a tableview with my data, and I believe I correctly pass that data using the didSelectRowAtIndexPath and the prepareForSegue functions.
My problem is that when I select a certain cell my cast becomes incorrect because I have a tab bar controller holding my views to be displayed with this segued information.
I want my cast to be:

let destination = segue.destinationViewController as! DownloadViewController

But I am getting an error because the segue is going to the tab bar controller first. This error makes perfect sense to me but I am unsure how to get around it without getting rid of the tab bar controller completely. Here is a picture of my story board to help show the overall flow.

https://i.stack.imgur.com/lRtq3.jpg

Any help is appreciated.

Destrif
  • 2,104
  • 1
  • 14
  • 22
John511
  • 19
  • 1
  • 7

2 Answers2

0

Instead of using segue, you can use a modal presentation of your desired first tab for display if it works for you.

let displayFirstVC = storyboard.instantiateViewControllerWithIdentifier("newVC") as! UIViewController
self.presentViewController(displayFirstVC , animated: true, completion: nil)

When you instantiateViewControllerWithIdentifier, you have to create a storyboard name for your FirstViewController with name newVC.

You would also need to replace UIViewController with the name you gave your view controller.

tp://i.stack.imgur.com/6MMsy.png

More details here. Instantiate and Present a viewController in Swift

Community
  • 1
  • 1
jo3birdtalk
  • 616
  • 5
  • 20
0

The UITabBarController has an array that contains its connnected viewController, to access e.g. the first one try

let destination = (segue.destinationViewController as! UITabBarController).viewControllers?.first as! DownloadViewController
Michael
  • 182
  • 1
  • 9