I'm trying to add UINavigationItem to my UIViewController as mentioned this answer. However the Navigation bar is not showing in my view. I tried even adding an outlet and setting the title programmatically and also adding the NavigationItem in two different places. Still it doesn't show. This view controller is embedded in a TabBarController. WHat am I missing here?
Thanks is advance.
This view controller is embedded in a TabBarController
But is it embedded, first and foremost, in a UINavigationController? If not, there will be no navigation bar that automatically appears and that automatically uses your view controller's navigation item.
If you don't want to use a UINavigationController (because you have no navigation to do), then you can add a navigation bar manually. But in that case your view controller's navigation item will not be used automatically to populate the navigation bar; you must populate it manually.
Typically, people do use a UINavigationController, even if there is no navigation to do, just to get this automatic behavior - to show the navigation bar and to populate it automatically.
[NOTE: The fact that you have told Interface Builder to show a navigation bar for this view controller, as if it were in a navigation controller, is irrelevant; that won't cause you to get any navigation bar when the app runs.]
Related
I’m having some trouble with a integrating a navigation controller inside a tabbarcontroller that is not in the root view. My issue is that the root view, which leads to the tabbarcontroller is embedded in a navigation controller. Naturally, since the root view leads to the tabbarcontroller then each tab uses that root view’s navigation controller. Ideally I’d like to wrap each tab in its own navigation controller so that I could adjust them accordingly. I’ve tried using a modal segue and it allows me to put each tab in its own navigation controller, but this implementation does not work due to a sliding side menu plugin I am using. Embedding a navigationcontroller in each tab causes my autosizing to think there are two navbbars (because there are.) Any ideas? Is there a way I can maybe remove the navigationcontroller from latter views and keep it on the root?
TabBarControllers are meant to be root controllers, so your best course of action is likely going to be restructuring the navigation of your app to fit this paradigm. If you don't want the TabBarController to be the first view that the user sees (for instance, if your app has a login screen) then you can just modally present the login view controller over the top of the TabBarController when the app starts up (if needed).
Barring that, if you're just looking for a quick fix for your double navigation bar issue, you just want to get around your double navigation bar issue, you could just set the Top Bar property for your NavigationController to "none", as shown below.
I am trying to connect a new empty View(homeScreen) from a ViewController (loginScreen) using Xcode 6 Beta 4 and Swift. A button triggers the segue to the homeScreen View. The problem is that when I add the segue, my blank/empty homeScreen View magically gets a Navigation Item Bar on top of the view.
You can see that without the segue my homeScreen View its empty:
After the segue it looks like this:
As you can see, Xcode inserts the Navigation Item Bar on top (grey rectangle). I would like to know how to get rid of it or how to create an empty View that remains empty even after assigning a segue to it.
Thank you so much for your help!
Cheers!
UPDATE: My goal is to create a navigation bar kind of like the one Facebook implements in its' iOS app. On top have the search bar and maybe some more icons. Does anybody know how to do that? I tried to hide the Navigation bar by selecting my view controller and in the Attributes inspector setting the "Top Bar" attribute to none, but it does not work. Any suggestions?
Thanks again.
Does loginScreen is inside a UINavigationController? If it is, the new showed view controller (homeScreen) is supposed to be in the navigation controller too, and thus it has a navigation bar by default.
You can hide it if you want, but then you have to find an alternative way to navigate in your navigation controller.
Otherwise you can present the homeScreen modally changing the type of segue to "Present Modally".
For more details on view controller presentation see this document plus some updates in iOS8 (WWDC session: View Controller Advancement in iOS8).
EDIT: To implement the FB-like navigation bar I would customize the UINavigationController bar:
read this AppCoda tutorial about customizing the bar
to add a search bar use the code like:
let searchBar = UISearchBar()
...
self.navigationItem.titleView = self.searchBar
This is because the segue is a "push" segue ("Show (e.g. push)") from a View controller that is already included in a Navigation controller. Therefore, it is put in the stack of views of this Navigation Controller, and therefore receives a navigation bar.
If you don't want a navigation bar, then use either a modal segue ("Present modally"), or a custom segue.
Same thing if you need a different navigation Bar (not linked to the first Navigation Controller). You can perfectly have a modal segue leading to a UIViewController, which is embedded in its OWN navigation controller (or having only a navigation bar). Have a look in the menu: "Edit / Embed / Navigation controller".
I'm making a custom navigation bar for my navigation controller based app, which has the default navigationBar hidden property set to true. Using the default navigation bar is out of the question because it was causing a lot of issues due to the degree in which I need to customize it (complex animations, changes in height, etc).
I'm currently adding my "navigation bar", which is just a UIView, to the view of the UIViewController. So of course, when I transition to a new view, the old navigation bar falls away and the next view controller doesn't have any navigation bar. What I'd like to do is make my navigation bar behave more like the default UINavigationController navigation bar, where it stays fixed to the top and the new and old elements cross-fade during the VC transition. How can I accomplish this effect without using a UINavigationBar?
Thanks so much!
You should use a custom container controller with your custom navigation bar at the top, and a view below to which you add a child view controller's view. That child view controller could be a navigation controller with its navigation bar hidden to handle the transitions. You would have to have the incoming controller (or outgoing I guess) send a message to the container controller to tell it to do the cross fade of its navigation bar.
I create a new XIB file, drag a UITabBarController in it, and then try to set the Top Bar to Navigation Bar.
No matter what I do, it goes back to Unspecified.
I think I should be able to set the Top Bar to Navigation Bar so I can lay out my views assuming I've got both a tab bar and a navigation bar, shouldn't I?
Is this intended behaviour???
I think this is an Apple way to remind you that UITabBarController is not supposed to be pushed in UINavigationController. Related question - Tab bar controller inside a navigation controller, or sharing a navigation root view.
I am trying to create a view with a TableView in the center, NavigationBar on top, and a TabBar with 5 items. The TabBarItems will be attached to 5 different modal views. And the tableview can select an item and "navigate" to another tableview or detail view.
Following the Apple doc, I tried to create a NavigationController in a TabBarController in IB, but failed. I read all the posting regarding to this topic, and they all described a NavigationController inside one of the TabBarItem. But that is not what I want. The TabBarController and NavigationController are separate controller doing separate thing in the same view.
So I start wondering maybe it is a design issue. I should just use a NavigationController and add the TabBar as objects and not controller in the view.
Am I going the right track or is there a better way to combine NavigationController and TabBarController in IB to do the job that I want. Am I making sense?
If the tab bar is actually being used as a tab bar, it sounds like you want 5 navigation controllers, one for each tab.
If the tab bar is being used as a toolbar to hold buttons that bring up modal view controllers, push views onto the navigation controller, or other actions besides what a tab bar is intended for, use a UIToolbar instead. UINavigationController actually has toolbar support built in, just set its toolbarHidden property to NO and set the toolbarItems property on each view controller that can go inside the navigation controller to an array of appropriate UIBarButtonItems.