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

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.

Keeping the current structure you can:
Embed ContactFormVC in NavigationController (editor -> embed in -> NavigationController) and on the NavigationController property uncheck "Shows Navigation Bar"
On both ContactFormVC and ContactDetailsVC set its "presentation" property (under "Transition Style") to "Current Context"; Your storyboard will look like this
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"

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.

Related

Why does a segmented control hide when using a TabBarController?

I want to use a segmented control inside a tab of a UITabBarController on iOS. It seems to work without it, but as soon as I embed it in a TabBarController, the segmented control won't show up in the navigation bar.
Am I missing something or is it just not supported because of some UI-guidelines? I haven't found anything in the Apple Design Guidelines...
This is the working version:
But in this setup, the segmented control does not show up:
First question is: What are you trying to achieve - what interface do you want to provide?
It is very uncommon to have a tab bar controller embedded in a navigation controller.
A tab bar controller is meant to be used as main app navigation. You can find it in so many Apple Apps (Music, Phone etc.)
These Apps have a tab bar controller with multiple navigation controllers. For example your first tab is a navigation controller with a normal view controller as root.
In this controller you then can set you segmented control.
Apple describes this behavior in it's Combined View Controller Interfaces Documentation (https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html#//apple_ref/doc/uid/TP40011313-CH6-SW1).
Update
#kaushal answer solves your problem ... yes. But if you will try to style the navigation bar for every view controller contained in your tab view controller (maybe you want to add a button as rightBarButtonItem only for one view controller) this won't work.
If you want a segmented control on every controller of the tab view controller just isolate the code for this control and reuse it in every controller.
This would achieve the same effect but you would have a cleaner software design.
try this :
Navigation bar is common throwout the stack, It will load once. And it was empty for first view. If you want it customisable for particular VC then you have to do it programatically by accessing self.NavigationBar in view did load method.

How to link a separate storyboard to each particular tab in uitabbarcontroller?

I have an app which has 5 major user flows..each flow is a few screens linking to each other...so each flow warranties its own storyboard. Each storyboard starts with a custom view controller that is embedded in a navigation controller. So far so good.
Now all of this is "stitched" together via a UITabBarController. This is the most default UI design ever known to iOS.
But turns out I don't really know how to link from tabbarcontroller, which is in its own storyboard (that is set as the main one on code project) to any of the other storyboards.
This problem looks so! simple, so I think I am missing something utterly obvious, but I just can't figure out how to do it.
So how do I link from tab bar controller in storyboard 1 to the initial view controller in storyboard 2 when a tab is tapped?
You should do this in code. You can have the tab bar controller (tbc for short) and the controller in the first tab in the app's main storyboard, and in the app delegate, instantiate the other controllers using instantiateInitialViewController. Create a mutable array by copying the tbc's viewController array, add the other controllers you instantiated to it, and then set that array as the tbc's viewControllers array.
You have to add your viewcontroller programmatically in tabbar.

Xcode 6 - Swift - Custom Tabbar with Navigation

I'm trying to create a tabbed application with navigation elements inside the tab bar, as seen in the picture below (the red bar) using Swift/XCode 6.2. Basically those three icons in the middle will direct the user to different view controllers. The other two icons would be context-based. For example, on a table view page you would see the menu icon and add new icon as seen in the image. However, clicking on a row would change the menu icon to a back icon, and the add icon to something else.
That's the general idea, but I'm having a very hard time implementing something even close to this. The first issue is that whenever I embed a view in a Tab Bar Controller, I can't move the tab bar to the top. However, when I create a custom UITabView in a View Controller, Control + Click and dragging a Tab Bar Item to another view doesn't create a segue. I haven't even begun to tackle having the navigation elements inside the bar.
I guess what I'm asking is just for a little guidance on what route to take to tackle this. I'm assuming I can't use a Tab Bar Controller or Navigation Controller because it doesn't seem like I can customize them all that much. So custom Tab Bar and Navigation Bars, and then implemnt the segues and button changes programmatically?
Thanks.
I will try to guide you from an architectural perspective (so you won't find much code below).
Using a UITabBarController
In order to achieve what you are suggesting, you are right you cannot use a UITabBarController straight away, among several reasons, the most immediate one is that they are meant to be always at the bottom and you want it in top (check Apple's docs). The good news is that probably you don't need it!
Note: If you still want to go with a UITabBarController for whatever reason, please see #Matt's answer.
Using a UINavigationController
You can use a UINavigationController to solve this task, since the UINavigationBar of a UINavigationController can be customized. There are multiple ways on how you can organize your view's hierarchy to achieve what you propose, but let me elaborate one option:
To customize a UINavigationBar's to add buttons, you just need to set its navigationItem's title view:
// Assuming viewWithTopButtons is a view containing the 3 top buttons
self.navigationItem.titleView = viewWithTopButtons
To add the burger menu functionality on a UINavigationController you can find several posts on how to do it and infinite frameworks you can use. Check this other SO Question for a more detailed answer (e.g. MMDrawerController, ECSlidingViewController to mention a couple).
About organizing your view hierarchy, it really depends on if when the user taps one of the main top buttons, it will always go to the first view controller in the new section or if you want to bring him back to the last view in the section where he was.
3.1 Switching sections displays the first view of the new section
Your app's UIWindow will have a single UINavigationController on top of the hierarchy. Then each of the 3 top buttons, when tapped, will change the root view controller of the UINavigationController.
Then, when the user changes section, the current navigation hierarchy is discarded by setting the new section view controller as the UINavigationController root view controller.
self.navigationController = [sectionFirstViewController]
3.2 Switching sections displays the last displayed view in the new section
This will require a slightly modified version of the above, where your each of your sections will have its own UINavigationController, so you can always keep a navigation hierarchy per section.
Then, when the user taps one of the top buttons to switch section, instead of changing as previously described, you will change the UIWindowroot view controller to the new section's UINavigationController.
window.rootViewController = sectionNavigationController
Using a custom implementation
Of course, the last and also very valid option would be that you implement yourself your own component to achieve your requirements. This is probably the option requiring the biggest effort in exchange of the highest customizability.
Choosing this option is definitely not recommend to less experienced developers.
I'd like to take a stab at this--I think it is possible to use a tab bar controller here.
Your topmost-level view controller will be a UITabBarController with a hidden UITabBar.
Each tab is contained in a UINavigationController.
All view controllers in the navigation controller will be a subclass of a view controller (say, SwitchableViewController).
In SwitchableViewController's viewDidLoad, you set the navigation item's title view (i.e. whatever's at the center; self.navigationItem.titleView) to be the view that holds the three center buttons. Could be a UISegmentedControl, or a custom view.
Whenever you tap on any of the buttons, you change the topmost UITabBarController's selected index to the view controller you want to show.
Issues you may encounter:
Table views inside tabs will have a scrollIndicatorOffset at the bottom even if the tab bar is hidden.
Solution: Play around with the automaticallyAdjustsScrollViewInsets of the tab bar controller, or the inner view controller. https://stackoverflow.com/a/29264073/855680
Your title view will be animated every time you push a new view controller in the navigation stack.
Solution: Take a look at creating a custom transition animation for the UINavigationController.

How to build navigation controller from existing view controllers drew in storyboard?

I have built some view controllers in storyboard like in the picture below
I already implemented the data inside them, modal segue is used for transitions in between. Now I just realise when I push "back" button, previous view won't be properly loaded. I figure I should switch to navigation controller and add those controllers in stack instead. But I don't know how to go from where I am now.
I think I should make changes programmatically because I found building navigation controller in storyboard won't have much variation in UI design (at least I don't know how to implement existing pages in that way). So what should I do to implement programmatically? Please help me, thanks!
Select Category View Controller and go to menu: Editor > Embed In > Navigation Controller. Then change segues style from Modal to Push.

iOS 7 - Add a view to a navigation controller and make it the first view to appear

Sorry if my title is a bit confusing and if it is basic but I've been trying to figure it out for quite some time.
I have 4 views already in my story board and they are all in a navigation controller, however, I need to add another view and make that newly added view my first view. I have added my view already, however, whenever I go to Editor -> Embed In -> Navigation Controller, I end up getting a new Navigation Controller.
Is there a way to use my existing Navigation Controller? Or am I forced to use/add a new one?
Sorry if this is a simple problem and I'm missing out on something basic. Thanks for any help.
You need to make "new" viewcontroller rootViewController of your UINavigationController.
Select your NavigationController,
Click and drag from NavigationController while holding your Control key down.
Drop on the new view controller.
Select rootViewController from the popup menu.
Once done, you should be all set.

Resources