I have been using the XLPagerTabStrip to effectively create a tab bar at the top of my view controller, with mutiple 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 view which once tapped segue to a new view controller (A2). I want to be able to get from A2 back to the first view controller displaying the child view controllers. I have tried add a navigation bar to both 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 mother view controller, 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).
Any help would be greatly appreciated.
Ok so I think there is a couple ways you can go about this. First the answer depends on what type of segue you're using. If you're using present modally then all you need to do is type
self.dismissViewControllerAnimated(true, completion: completion)
Otherwise see below for methods to segue back to the A1ViewController.
First Option:
You could embed the Mother View Controller in a UINavigationController. The Mother View Controller would then be the root view controller for the UINavigationController and you would be able to use
navigationController?.popToRootViewControllerAnimated(true)
Second Option:
An unwind segue. These segues are perfect for going backwards and can be implemented in 3 steps.
Create an unwind method in the controller you want to return to. (In your case the method would be in controller A1)
@IBAction func unwindToA1ViewController(segue: UIStoryboardSegue)
See below for a further explanation and great visuals! https://www.raywenderlich.com/113394/storyboards-tutorial-in-ios-9-part-2
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.