I have two view controllers. I have navigated from one view to another view by press the button to using below code.
*let secondViewController = self.storyb
Here we go.
This line will give you a array of UIViewControllers
self.navigationController?.viewControllers
Now what you have to do is check your viewControllerObject does exist or not?
By writing this line
if viewController.isKindOfClass(YourController){
}
and here is a complete code.
if let viewControllers = self.navigationController?.viewControllers {
for viewController in viewControllers {
if viewController.isKindOfClass(YourController) {
print("Your controller exist")
}
}
}
When you write below line while going back to your 'ViewControllerA' it will remove a ViewControllerB from navigation stack.
self.navigationController?.popViewControllerAnimated(true)
It is just similar pop operation which we are doing with stack and navigationcontroller is a stack.
Let me know if you have any confusions.