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
To check whether the navigation stack contains a particular type of view controller, you can use:
if let viewControllers = self.navigationController?.viewControllers
{
if viewControllers.contains(where: {
return $0 is YourViewController
})
{
//Write your code here
}
}
To remove a particular controller from navigation stack, you need to make changes to the navigation stack.
Example:
if var viewControllers = self.navigationController?.viewControllers
{
for controller in viewControllers
{
if controller is UIViewController
{
viewControllers.removeElement(controller)
self.navigationController?.viewControllers = viewControllers
}
}
}