0

i can change my ViewControllers from navigation hierarchy using self.navigationController?.setViewControllers by passing my desired Viewcontrollers there but i dont how to do the same on my case :

i have 3 tabs say A,B,C

and from A i can push to A2 view controller

and from B's B1 i can also push A2 view controller (open A2 viewcontroller via segue ) but when i'm in this A2 View controller i want to change the View controllers in navigation hierarchy , if i go back from A2 it should took me Tab A how can i do this ??

p.s. if my question is not clear enough then let me know i'll fix it.

remy boys
  • 2,928
  • 5
  • 36
  • 65

1 Answers1

0

You shoul instantiate ViewController A in this case and can pop to that specific viewController by using popToViewController method.

for example,

  let viewController = self.storyboard?.instantiateViewControllerWithIdentifier(identifier) as UIViewController
  self.navigationController!.popToViewController(viewController , animated: true)

or can manage something like,

   let viewControllers: [UIViewController] = self.navigationController!.viewControllers as [UIViewController]
  self.navigationController!.popToViewController(viewControllers[viewControllers.count - 2], animated: true)   //manage index or array that can reach you a your viewcontroller A

You can get your tabbar's tab (i.e. viewcontrollers) somthing like,

  var vcA:FirstViewControllerA = self.tabBarController.viewControllers[0] as FirstViewControllerA!

and can pop to that vcA.

Reference : this so post

Community
  • 1
  • 1
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75