Mahesh Babu Mahesh Babu - 2 years ago 122
iOS Question

iOS Navigation Back Button

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?

Answer Source

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)

OR If Class A is your RootView controller

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download