Reputation: 18
I’m having a scenario, I had 3 controllers, lets assume A,B and C. When app launches I’m transitioning from A to C using segue. Later, in C by using a button I’m moving to B using segue again. So, now I’m in B when I click “Back” it is transitioning to C, but it has to move to A.
How is this possible, any hint/idea?
Upvotes: 0
Views: 556
Reputation: 2640
Put this code in B controller's back button.
for viewcontroller in self.navigationController!.viewControllers as Array {
if viewcontroller.isKindOfClass(HomeVC) { // change HomeVC to your viewcontroller in which you want to back.
self.navigationController?.popToViewController(viewcontroller as! UIViewController, animated: true)
break
}
}
OR If Class A is your RootView controller
self.navigationController?.popToRootViewControllerAnimated(true)
Upvotes: 1
Reputation: 615
If your Class A viewController is root, you can set this code on back button:
self.navigationController?.popToRootViewControllerAnimated(true)
Upvotes: 0