Segue back from Modal to First Tab Bar

断了今生、忘了曾经 提交于 2019-12-25 03:07:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!