Reputation:
I created an iOS app with Xcode and Swift. My Storyboard
contains five ViewControllers
managed by a single TabBarController
.
Is there a way to perform a segue from a UITabBarController
to a UIViewController
without the TabBar at the bottom disappears?
Upvotes: 1
Views: 2481
Reputation:
Solution:
I was asking this question to handle QuickActions this way. Here's the working solution, without the TabBar disappears: https://stackoverflow.com/a/37710017/6423177
Upvotes: 1
Reputation: 776
If you're performing segue from UITabBarController
to the UIViewController
, you cannot keep the TabBar
showing, although if you perform segue from on of the view controller
(i.e. a tab) to the UIViewController
the TabBar
will not be hidden.
Upvotes: 0
Reputation: 7466
UIWindow root
|
UITabbarController
|
|- UINavigationController - navigationStack
| |- 1 - SomeViewController
| |- ...
| |- ...
| |- N'th...SomeViewController
|- SomeViewController
|- SomeViewController
|- SomeViewController
This above is the correct view controller hierarchy. Trying to do it any other way doesn't make any sense. In the example I only embedded the first set of controllers inside a navigation controller. It will do what you asked for. You can use this embedding in any of the tab bar positions.
The TabBarController uses VC containment to show controllers. You can embed your controllers like this
Upvotes: 1
Reputation: 1093
If the view controller you are segueing to is among the tab bar view controllers then all you need is:
self.selectedIndex = INDEX_OF_VIEWCONTROLLER_IN_TABS
That will move to the controller as though you tapped on a tab.
So, you can do let tabVC = storyboard.instantiateViewController("TABIDENTIFIER") as! UITabBarController
(or CustomTabBarController)
then select the index tabVC.selectedIndex = index
Upvotes: 0
Reputation: 4341
The best way to implement this is to wrap your view controllers contained in the tab bar controller in a UINavigationController. Then inside of that view, you can push the new view onto the Navigation Controller and preserve the Tab Bar controller.
Check out this link about combining view controllers https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html
Upvotes: 1