Search code examples
iosswiftmodal-dialoguistoryboardseguetabbarcontroller

Where to put the Dismiss button for a modal TabBarController


I launch a Tab Bar Controller from my view with a segue. After editing the passed data, I need to dismiss the tab controller. The storyboard in Xcode won't allow me to add a Dismiss button on the Tab Controller (and shown on all the tabs.) Do I have to have a separate Dismiss button on each tab view? That seems rather clunky.

What's the best way to handle this?


Solution

  • Each view which is connected to a tab bar in the Tab Bar Controller is a completely separate view. The tab bar just holds them together. If you would like to have a back button, you do have to have a separate button or gesture action on each view in the tab bar.

    However, you can easily dismiss the view with code instead of having to add four extra segues.

    self.dismissViewControllerAnimated(true, completion: {})
    

    That line will dismiss your current view controller.