问题
I have two TabBarController views embedded in a NavigationController and one View presented modally with its own NavigationController:
FeedView (1) (TableViewController -> Contained within TabBarController)
VenueView (2) (CollectionViewController -> Contained within TabBarController)
SelectView (3) (ViewController -> Modally presented from VenueView)
In VenueView (2), I have the following code to bring up SelectView (3):
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let selectNavigationController = self.storyboard?.instantiateViewControllerWithIdentifier("selectNavController") as! UINavigationController
let selectVC = selectNavigationController.topViewController as! SelectViewController
selectVC.currentVenue = venueItems[indexPath.row]
presentViewController(selectNavigationController, animated: true, completion: nil)
}
This allows me to bring up SelectView(3) without the tabbarcontroller, but still have a navbar. I have a button in SelectView(3) which I would like to use to persist an object's data and segue into FeedView(1).
I've tried many methods but the closest I've got to success was to segue to FeedView(1) but add more viewControllers (evidenced by buttons in navbar) and not have it contained within the TabBarController.
What is the correct way of creating this segue? I know how to persist the data but my question is more related to the proper technique of segueing from a modal View to the first tab of a BarTab.
Pic below for reference:
回答1:
You could use an unwind segue if you stayed within the same navigation stack. However, FeedView is on a different navigation controller.
One way to do it is to have your TabbarController switch back to FeedbackView (1st tab) using:
tabBarController.selectedIndex = 0
来源:https://stackoverflow.com/questions/32061740/segue-back-from-modal-to-first-tab-bar