I'm trying to set the currentVC as the delegate for the destinationVC that is being navigated to through a UITabBarController and embedded in a UINavigationController.
I cant set the current VC as the delegate because prepareForSegue never gets triggered and the other solutions provided doesn't work either (bottom code).
This was all set up as Storyboards with Interface-builder
This is the architecture:
--> UITabBarController
-->UINavigationController
--> currentVC (Set this as the delegate)
-->UINavigationController
--> destinationVC
This does nothing:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print ("The Segue was triggered")
let destinationVC = segue.destination as! MyViewController
destinationVC.delegate = self
}
I also cant get this to work (it never goes through the IF statement):
override func viewDidLoad() {
super.viewDidLoad()
if let myDestinationVC = (self.tabBarController?.viewControllers![0] as? UINavigationController)?.viewControllers[0] as? destinationVC {
print ("The IF statement was triggered")
myDestinationVC.delegate = self
}
}
I have a custom class for my TabBarController, that doesn't really do anything right now - I'm not sure if I need to reference that in the code above?