Passing data through segues when called dynamicly
tl;dr: I don’t. I grab the top view controller from the stack of the navigation controller.
From my DetailView, I wanted to push to a new ViewController for adding a comment. The “link” to add a new comment was in an action sheet (UIAlertController), so I had to call the segue from the code. To create the segue in the StoryBoard, I had to connect the NavigationController (not the UITableViewController) with the new ViewController.
This means, that when I call
self.navigationController?.performSegue(withIdentifier: "downtimeSegue", sender: self)
the segue will be perform correctly. BUT. The method
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
will not be called since it is implemented in my DetailViewController, not in the NavigationController.
So I am not able to pass any data in that method.
Solution: I just grabbed the DetailViewController via the NavigationController and so I can access all properties.
override func viewDidLoad() {
for controller in navigationController!.viewControllers {
if controller is DetailViewController {
self.delegate = controller as? DetailViewController
}
}
}