I have a 3 view controllers, A->B->C but between B and C I have a navigation controller. My C controller is getting some information from the user and I am saving it in Realm(local database). When exiting that controller I want to go to the B controller and show some of that data saved, however, when I try using popToViewController it tells me that either the controller doesn't exist or it just crashes. I have also tried
dismiss(animated: true, completion: nil)
but it only exits the controller and doesn't reload the data on my B controller. Is there a way to use PopToViewController in Swift 4?
This is how I have tried using it:
let prevVC = self.storyboard?.instantiateViewController(withIdentifier: "FormListVC") as? FormListVC
navigationController?.popToViewController(prevVC, animated: true)
I have also tried:
for vc in self.navigationController!.viewControllers {
if vc is FormListVC {
navigationController?.popToViewController(vc, animated: true)
}
}
But nothing happens.
You are saying when you
dismiss(animated: true, completion: nil)then your view controller exits.This implies your controller is not in the navigation controller but presented modally. So the popToViewController won't work.
If you want to pass data back to your controller after dismiss, use Delegates.