How to add UIToolbar to a NavigationController on Storyboard? - ios

I am not a huge fan of using Interface Builder and for that reason I am new to it.
I am trying to add a UIToolbar to a navigation controller but because Apple documentation is always very clear, I don't have a clue.
I am converting an old project to use Storyboards.
This is what I have done.
I have added a storyboard to the project
I have added a navigation controller to it
Because I want this navigation controller to show a toolbar at the bottom, I have clicked on the navigation controller and turned the toolbar on (see pic).
after that, a white rectangle appeared at the bottom of the navigation controller on interface builder. I think this is a the UIToolBar or a placeholder. I have tried to drag a BarButtonItem to this "space" and Xcode allowed, showing it like this:
When I run the app, the toolbar shows as a white rectangle at the bottom but not the button.
The button shows like this on the hierarchy:
I suppose the button should be inside the Toolbar item, but Xcode forbids dragging the item there.
How do I make the button show?

The problem here is that your are trying to add an UIToolBar in a UINavigationController ...
Try in an UIViewController and that will work !
Edit:

Try this :
You just drag and drop the UINavigationItem on UINavigation RootViewController instead of UIToolbar.
It will allow you to put UIBarButtonItem on that UINavigationItem and works same like UIToolbar Button.

Related

How do I add a UIBarButtonItem to a navigation bar?

Prior to iOS 8 I could simply drag the UIBarButtonItem from the object library to a navigation bar. But now I simply can't if it is not the first view controller on the navigation stack.
I know I can do it in code but is there any way I can make it happen in Storyboard?
Yes you can. First drag-drop a UINavigationItem to your ViewController. This will add a title bar. Then drag a UIBarButtonItem and drop in the nav bar. This works.

Why can I not drag UIBarButtonItem onto navigation bar?

I'm having a little bit of an issue. When I place the UIBarButtonItem on the tab bar controller it works perfectly, it displays as it should:
However, I can't put a button onto where the black square is. Does anyone know how I could do this non-programatically?
You should probably add a Navigation Item by dragging it from the Object Library to the place where you have marked in black and then try adding a Bar Button Item on the right. It should work
UINavigationBar wants only UIBarButtonItem. You can create one with custom View programmatically. Show here: https://stackoverflow.com/a/16058345/717193

How to add buttons to navigation controller visible after segueing?

I have set up a view controller in Storyboard which is embedded in a navigation controller. In this nav controller I have checked Shows Navigation Bar and Shows Toolbar and enabled a navigation bar and toolbar in Top Bar and Bottom Bar respectively in Simulated Metrics. I then "Show e.g. Push" segue from the view controller to another view controller. On both view controllers I've set up Simulated Metrics the same way, so both the navigation bar and toolbar are visible on all three controllers.
The problem is, I can add bar button items to the first view controller to both the navigation bar and the toolbar, but I cannot add a bar button item to the navigation bar on the second view controller. When I drop a button on the navigation bar, it's added to the toolbar instead. And I cannot double click the nav bar to add a title. In the outline I see there is no navigation item on the second view controller, but it is there in the first view controller.
I can probably add buttons to the navigation bar programmatically, but I want to do this visually in Storyboard. My question is, what is wrong with this setup, or is this a bug with Xcode?
For XCode 6, the UINavigationItem for the 2nd view controller onwards is not added automatically on the View Controller Object inside the storyboard. You will have to drag the UINavigationItem onto the Navigation Bar for that view Controller Object before adding UIBarButtonItem on top of it.
I am not sure why it is designed that way. I only discovered about this a few weeks ago.
If you have a ton of view controllers and very little custom auto-layout stuff in place, you can disable size classes, then re-enable it will add all missing nav bars across your storyboard.
Obviously not recommended if you have a ton of custom auto layout stuff linked up.
If you have just a single UIViewController that's missing a nav bar, just drop a UINavigationItem onto it.
If you're using Xcode 7 beta 4/5, try restarting Xcode it solved the issue for me
I just bumped into this issue and it seems to be affected by the segue that shows the view controller.
If "Kind" setting in segue is "Show (e.g. Push)", it's not possible to drag the item to top right corner. However, if you explicitly change "Kind" setting to "Push", this can be done.
Edit: actually I just noticed that "Push" is deprecated. Not sure what Apple is thinking here. However, you can just change it back to "Show" after adding the button and it seems to work :D
For second view controller in hierarchy, you can setup title in attributes, without adding "navigation item"
I think it is a bug. I had the same problem.I fixed this problem by disable the size classes, then enable it.
You can disable and enable the size classes in Interface builder doc.
It's very simple. You just need to use navigaitonItem first as the holder of the buttons and then you can add barButtonItems on top of that.

How to hide the UITabBar and show UIToolBar?

I read several answers to this question but couldn't figure out how to do it. I'm using Xcode 4.2 with ARC and no storyboards.
I'm developing an app based on the TabBar application template and extended it to contain 4 UITabBars. I'm not using UINavigationController but instead using UINavigationBar next to the status bar. When the app is loaded with the first tab shown, I have a button on the UINavigationBar and when I press it, I want to hide the UITabBar and instead show the UIToolBar at the same location where the UITabBar was located.
I tried to hide and show using the hidden property (hiding the UITabBar and showing UIToolBar). What happens is the UITabBar is hidden but the UIToolBar is shown above the location where the UITabBar was shown before. This looks ugly and I want it to be shown at the very bottom of the screen.
I think I can't use hidesBottomBarWhenPushed as I don't use a UINavigationController but instead using Navigation bar directly.
Also, I want to revert back to showing the UITabBar and hide the UIToolBar when pressing the same button on the UINavigationBar.
I am not sure if my idea would work for your scenario. Here it is...
but before, just let me tell you that hiding UITabBar, unlike hiding UINavigationBar is not animated. So to me, hiding tabBar is not a user-friendly approach, unless you create your own subclass of UITabBarController that animates hiding the UITabBar.
You can use presentModalViewController:animated and dismissModalViewControllerAnimated: methods. The viewController that is being shown modally can have a UINavigationBar, it pops out from the bottom of the screen and covers the UITabBar with animation.
Hope that helps.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

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