UITabBarController Header with Title - ios

I have been trying to hours to implement a simple UITabBarController where each view (or tab) has an active header (or top bar) with the title of the view. Is there a way in Xcode 6.1.x to create a UITabBarController with pages whose title is reflected in the top bar?
As it currently stands, I cannot get the top bar to show. I'd prefer not to drag navigation bars to each view and do this manually. Also UINavigationControllers are not necessary here, as each tabbed view will only need to display a single page.
Thank you.

Changing the values of those simulated metrics fields on a storyboard or nib will not actually have any effect on the UI. It's a design/layout aid.
You will need to embed the view controllers within navigation controllers or drag navigation bars into the views.

Related

Tab Bar implementation within single view application

I've searched for a suffice answer to this question but I've been unable to come across one that fits my dilemma. How do I implement a tab bar within my already single view application? My storyboard consist of four view controllers, a navigation view as the initial view, and 3 following table views. Now i know the order of containment must have the tab bar controller first so i embedded my navigation controller with a tab bar controller. doing this has given every view controller on my storyboard a dark gray tab bar silhouette on the bottom of each view, so i have no way of manually editing and selecting my tab bar views.
My goal is to assign my third table view controller in my storyboard as the first tab bar item. how should i do this programmatically? the first view controller acts as the default for the tab bar item. how do i change this programmatically?
here is screenshot of my storyboard:
https://41.media.tumblr.com/c3146efea93d2aeeccdcc55a6104674d/tumblr_nqqlieVI8f1tupbydo1_1280.png
here is the documentation provided by apple on the correct coding to properly assign and configure your views but its very depreciated:
https://40.media.tumblr.com/172a516075baed44cde104abf50d91aa/tumblr_nqqmngJLoA1tupbydo1_1280.png

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.

Sharing a UINavigationItem among different ViewControllers

I have a requirement to implement an app that has a navigation bar like bar at the top of numerous screens.
It has an icon on the left, some text, and some buttons on the right thus these would map well to a navigation item's left bar button items, title view, and right bar button icons.
However on most of the screens the content of the bar remains the same - i.e. a back button and title change would only appear occasionally for some screens, and on others the navigation bar would be present but is not actually used for navigational purposes.
Is the best of implementing this to configure a UINavigationItem, if so as there are multiple screens and multiple view controllers is there anyway the same UINavigationItem can be shared? That way I can configure the UINavigationItem in the RVC and keep it there as different view controllers get pushed, replacing it where need be when a back button does actually need to appear?
If this isn't the best approach then what alternatives are there? I experimented with making my RVC a container view controller and adding the bar as a view of that, that works for the immediate child view controllers but not for grandchild view controllers (which would take up the entire screen and not the portion alloted to them by the container view).
The navigationItem in UIViewController is readonly, so you can't have a single shared UINavigationItem shared between view controllers. You could have a base view controller class that manages setting the navigation item that you derive all of your view controllers from. To keep your classes from getting too coupled you could have it update the contents of the navigationItem from a NSNotification. Then you can just post a notification when you need all of the navigation items to be updated.

ios - why do some of my screens have a navigation controller and some do not

Below is a storyboard of my app. For some reason, some of the screens have a navigation bar on top, and some do not. How can I add the navigation bar to each of the screens? Any thoughts on what I did incorrectly for this to happen?
Thanks!
There's a couple gotchas here to be aware of:
The Simulated Metrics, as mentioned by #ohr, are just there for convenience when laying out your views. This lets you account for potentially having the 44px navigation bar in place, so you know to layout your UI elements on your view accordingly. This does not mean you have a navigation controller (or navigation bar) actually within the view.
To have a functional navigation bar, you have a couple options:
1) In your Storyboard, embed your UIViewController within a UINavigationController. This can be done by clicking Editor in the Menu, then Embed in -> Navigation Controller. Make sure you have your desired view controller in the storyboard selected.
2) If you just need a one-off navigation bar (say you are displaying a modal and don't need to push views onto the view hierarchy), then you have the option of just dropping a UINavigationBar into your storyboard view controller. You'll just need to wire up the buttons to IBActions to have them perform the desired task.
Hope this helps!

How do I add a search bar below the nav bar in a UISplitViewController?

How do I add a static search bar (one that doesn't scroll with the UITableView) below the UINavigationController in the root view of a UISplitViewController. The iPad mail app has an example of one of these. Actually I would Ike to add a toolbar with a segmented control instead of a search bar, but I imagine the process is the same.
Yes I meant the left pane of a UISplitViewController, so I guess my question is really
how should I add a static toolbar below the navigation bar when using UITableViewController?
You can add any view (except the new iPad split view) to a navigation controller, not only a UITableView. And the added view may have subviews...
Add a plain UIView to the NavigationController.
In this UIView, add your searchbar first and then your navigation controller below the search bar. You can even add a toolbar at the bottom.
NavigationController
UIView
searchbar
tableview
toolbar
Umm... can you re-word this? Do you mean in the left pane of the UISplitViewController? There is no UINavigationController allowed as the parent of a UISplitViewController -- it gives a runtime error in SDK 3.2.
If what you are saying is essentially "How do I add a search bar in the left pane of a UISplitViewController? Then the answer is the same way you would for any view you display as the left pane. Since both panes take simple UIViewControllers (not just a UITableView), you build a nib in IB with the view, the search bar, below that you then put a UITableView. This is the NIB you assign in the so called "Master interface" (left side).
Most people that have this kind of question think that you can only use a UITableView in the "Master Interface" (since that is what it looks like is happening).

Resources