0

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?

  • If you're moving in direction of A -> C -> B, how can you think is possible to go "back" to A from B? O.o You can skip the C controller, but it's not the meaning of "back" – Luca D'Alberti Jun 03 '16 at 13:18
  • assign the tag properly on your question in which language you ask – Anbu.Karthik Jun 03 '16 at 13:19
  • 1
    Check out [unwind segues](http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them) – Matt Le Fleur Jun 03 '16 at 13:21

2 Answers2

1

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)
Bhadresh Mulsaniya
  • 2,560
  • 1
  • 10
  • 24
0

If your Class A viewController is root, you can set this code on back button:

self.navigationController?.popToRootViewControllerAnimated(true)
DoN1cK
  • 492
  • 7
  • 19