Search code examples
iosswiftuitabbar

Add Main Tab Bar to Other View Controller


I'm a new Swift developer. I'm using Swift 4.2 and XCode 10.2.

I have a tab bar controller with 5 tab bar items. In the view controller for each tab bar item there is a button to show the balance in a different view controller (call it the Balance View Controller). I have a segue from each button to the Balance View Controller.

I am using interface builder, but will be happy to add code.

How can I put the main tab bar on the Balance View Controller so when the user is done viewing the balance, he can select another tab bar item and keep going? I rejected using a navigation controller because the back button will interfere with the uniform view at the top of every screen and I don't want to adjust it.

I could not find any SO questions that address this issue. And all the other web resources I found are very basic on how to implement tab bars. Any help would be appreciated.


Solution

  • Another approach:

    Load Balance View Controller as a Child ViewController, and display its view on top of the current view. This will leave the tab bar alone, allowing users to navigate to another tab.

    Balance View Controller sounds like it's just an information display. If so, you can add a tap gesture to remove it from the current view on a simple tap.

    If Balance View Controller is interactive, you can add a button to remove it from the current view.

    Since you say you have a button in each tab's VC to show the Balance View Controller, then you probably also want to remove it from the current view when another tab is selected.