Segue from modal view to tab bar view controller and not lose tab bar

删除回忆录丶 提交于 2019-11-26 11:16:33

问题


Hello Im trying to segue from a modal to a tab bar view controller without losing the tab bar? I know the question is short, but this is all I\'m asking.

Scenario: I have a Tab Bar View Controllers, A and B. B modals to C view controller. Then I want to return to View Controller A.

Swift please :D


回答1:


Here is my example of how to do this. In my setup, I choose the yellow ViewController from the tab, then press Go! which modally presents the white ViewController. Pressing Exit returns to the green ViewController.


To set this up, use an unwind segue to return to the viewController that called you. For instance, implement this in the first ViewController of the tab (the one calling the modal segue).

@IBAction func backFromModal(_ segue: UIStoryboardSegue) {
    print("and we are back")
    // Switch to the second tab (tabs are numbered 0, 1, 2)
    self.tabBarController?.selectedIndex = 1
}

Then switch to another tab using self.tabBarController?.selectedIndex = n where n is the number of the tab you really want to go to. To set up the unwind segue, you can either control-drag from a button in your modal view controller to the exit icon at the top of the viewController and select backFromModal from the pop up...


OR

you can set up the unwind segue to be called programmatically by control-dragging from the viewController icon at the top of the modal viewController to the exit icon, and select backFromModal from the pop up.

Then, go to the Document Outline View and click on the unwind segue

and give it an identifier in the Attributes Inspector on the right (for example "returnFromModal").

Then you'd call the unwind segue like this:

self.performSegue(withIdentifier: "returnFromModal", sender: self)


来源:https://stackoverflow.com/questions/30991551/segue-from-modal-view-to-tab-bar-view-controller-and-not-lose-tab-bar

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