0

I have a base UIViewController called BaseController and it is invoked via a segue in my storyboard. Now I have two subclasses of this baseController - Subclass1 and Subclass2. I want to invoke SubBaseController1 or SubBaseController2 depending on the target when the segue gets triggered. How do I instantiate SubBaseController1 in target1 or SubBaseController2 in target 2 when the segue gets invoked?

PGDev
  • 22,484
  • 6
  • 31
  • 76
Deepak Sharma
  • 4,751
  • 5
  • 44
  • 106
  • Does this answer your question? [IOS - How to segue programmatically using swift](https://stackoverflow.com/questions/27604192/ios-how-to-segue-programmatically-using-swift) – Maciej Gad Nov 05 '19 at 08:03

1 Answers1

0

You can do it in two way:

  1. Use two different segues. Add identifiers for both, similar to this picture Segue Id and then call this code to open the correct screen
performSegue(withIdentifier: "segue1", sender: nil)
  1. Don't create any segue, but add storyboardId to view controller, similar to this: Adding storyboardId and use this code to init and show view controller:
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let viewController1 = storyboard.instantiateViewController(identifier: "viewController1")
present(viewController1, animated: true)

I will recommend the second way as it gives you more control over the displaying process.

Maciej Gad
  • 1,561
  • 16
  • 21