0

I have been using the XLPagerTabStrip to effectively create a tab bar at the top of my view controller, with multiple child view controllers displayed within it (source : https://github.com/xmartlabs/XLPagerTabStrip)

Lets call these child view controllers A1, B1 and C1. Within the child view controllers are table views which once tapped segues all the child view controllers to a new view controller (A2). I want to be able to get from A2 back to the first view controller. I have tried add a navigation bar to all the child view controllers and using the navigationController?.popToRootViewControllerAnimated(true) method, but when a button containing this code is pressed nothing happens. I have also tried embedding a navigation controller within the initial view controller hosting the child view controllers, but this also doesnt work (not sure if this is because the child view controllers A1, B1 and C1 are not connected to the mother view controller within the storyboard).

Ryan Hampton
  • 319
  • 1
  • 4
  • 21

1 Answers1

2

Set the storyboard id of your view controller. Then:

let vc = self.storyboard?.instantiateViewController(withIdentifier: "someID")

Swift 2

self.showViewController(vc, sender: self)

Swift 3

self.show(vc, sender: self)
Community
  • 1
  • 1
Pranav Wadhwa
  • 7,666
  • 6
  • 39
  • 61
  • thank you. I changed the last line of your code to self.showViewController(vc, sender: self) to make it work though so might be worth editing your answer :) – Ryan Hampton Jun 21 '16 at 16:06
  • Not really the best option. `vc` is a new instance, it won't magically reuse the previous one. Embed A1, B1 and C1 in a `UINavigationController` and you have your controller stacks. – Luca D'Alberti Jul 21 '17 at 07:20