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

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!

Related

do I need to embed navigation controller if I want to make custom navigation bar view?

I need to make a custom navigation bar, since it will have search bar and some other views, it will be easier if I just make custom view instead of inserting view to navigation controller programatically
like the picture below, there are 2 ways to implement custom navigation bar view, by embedding navigation controller (yellow VCs) and use or just using present modally segue (blue VCs)
personally I will choose to use navigation controller because 'maybe' there are some methods that has already built that I can use. but the problem is, the custom navigation view (red color) in navigation controller it seems overlapped by the actual navigation bar in storyboard, I don't know how to hide the navigation bar from navigation controller in storyboard, even though if I use self.navigationController?.setNavigationBarHidden(true, animated: animated), it won't be a problem.
what is the right approach to make custom navigation bar like this?
In IB the navigation bar is shown only to simulate what it might look like when you run the app. The decision to show this is inferred, by default, by the fact that it is downstream from the navigation controller. Luckily you can change this option.

UITabBarController Header with Title

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.

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.

Hide Navigation Bar in Interface Builder w/ Storyboards

I have a pretty basic storyboard based app, with a UINavigationController, a main view and a secondary view, both of which are in the navigation hierarchy. I’m currently hiding the navigation bar on the main view by using setNavigationBarHidden: as appropriate in viewWillAppear and viewWillDisappear. It seems like there should be a way to do this in Interface Builder, rather than in code. Essentially I’d like the options available in the Simulated Metrics options, but not simulated. Does that exist?
In the scene for the UINavigationController itself, I suppose you could check the hidden button for the nav bar in the Attributes inspector, but that would make the nav bar hidden for all the view controllers in the navigation stack. But that's not what you want.
To hide the nav bar for an individual view controller using IB, you would need to use a stand alone nav bar for each view controller (e.g., drap and drop a Navigation Bar from the object library in IB). To use a stand alone nav bar in a navigation stack would be more work than programmatically hiding the nav bar.
Just uncheck the Attribute Inspector > Shows Navigation Bar in Attribute Inspector

Using iOS 6 autolayout, what would be the proper way to display somthing above an UINavigationController?

In my app, i have a main view controller which sometimes brings a modal view on top of it. This modal view is a UINavigationController with a navigation bar. I want to display an image above the navigation bar, and have the navigation bar appear below the image.
I do not want to subclass anything and the app uses autolayout, i do not want a bunch of delegate callbacks and frame calculations. The view inside the navigation controller (the actual modal content) must still respond to different screen sizes correctly, such as rotation, call status bar etc. Also, no IB solutions please, these views are all managed in code.
How do i accomplish this?
I would turn off AutoLayout and place the image at the top
I don't think you can do it with your modal view being a navigation controller. I would do it by making that modal controller a UIViewController that you set up as a custom container controller. You can add an image view to the top of this controller's view and add the view of a child view controller (which would be a navigation controller) to the bottom. This would be a lot easier to do in a storyboard using container views, but it certainly can be done in code.

Resources