user6465101
user6465101

Reputation:

Use Segmented Control with TabBarController without TabBar (on bottom) disappears

I want to use Segmented Control to choice between contact form and contact details in the contact ViewController in my app. The contact ViewController is managed by the TabBarController. But when switching by using the Segmented Control the TabBar on the bottom disappears.

I uploaded a sample project here: SegmentedControlTest

Is there a simple way to solve that issue?

Regards, David.

Upvotes: 0

Views: 1428

Answers (2)

Dickson Leonard
Dickson Leonard

Reputation: 518

Keeping the current structure you can:

  1. Embed ContactFormVC in NavigationController (editor -> embed in -> NavigationController) and on the NavigationController property uncheck "Shows Navigation Bar"
  2. On both ContactFormVC and ContactDetailsVC set its "presentation" property (under "Transition Style") to "Current Context"; Your storyboard will look like this enter image description here

You should change your transition to push and pop instead of both "show" otherwise you'll keep adding on the navigation stack. It's easy to do via code, I can't find how to do this via storyboard. I also recommend changing the structure for your view controllers as suggested by previous answer.

The way I encourage you to do is to use single view controller with multiple container views.

*Connecting .swift code to storyboard. Make sure the class name on custom class section is the same as the class' name. In this case it's "ViewController.swift" enter image description here

Upvotes: 0

酷酷的哀殿
酷酷的哀殿

Reputation: 1051

I download your sample project. As your segue's type is show,and you want didn't want to disappear tabbar,I guess you only want to exchange the form view with detail view.Not show another viewcontroller.

You can solve it by create detail view not detail view controller.

An alternative solution is that you can change UITabBarController's viewControllers.

Upvotes: 0

Related Questions