I have the following hierarchy in my app: UITabBarController to many UINavigationControllers. Each navigation controller has a UIViewController.
I’ve split this up so that each UITabBarController’s child view controller is linked via a storyboard reference. In each of these references there’s a UINavigationController as the initial view controller.
Again some of these other storyboard references are split up too, where one of the UINavigationController’s child view controllers also uses a storyboard reference.
These UINavigationController’s child view controllers in the new storyboards do not carry across the UINavigationController style. Unlike the UITabBarController which does take across the UITabBarItem and shows them in the UINavigationController.
Is there anything I can do to see the navigation item of these UINavigationControllers so I can add bar button items in IB?
It's straight forward really; just go to Editor > Embed In > Navigation Controller and embed your view controller in a UINavigationController. You can then select the UIBarButton items under the Object Library in xCode, drag and drop them to the navigation bar on your View Controller and voila!
You can then delete the UINavigationController when done with adding the UIBarButton items to your VC; those bar button items will still be referenced and shown in the final product when you run it.
In Storyboard go to the Attributes Inspector for the Controller you wish to add the navigation bar and click on top bar drop down instead of it saying 'inferred' click on 'Translucent Navigation Bar'
Related
Back when I first created the foundational layout for the app I'm currently working on in Storyboard, I did it in two steps:
Selected my View Controller and used Editor->Embed In->Navigation Controller.
Selected my View Controller again and used Editor->Embed In->Tab Bar Controller.
This was the resulting layout:
Question 1: Why do these steps create such an odd layout?
In this weird layout that seems to imply that the Navigation Controller is attached to the Tab Bar Controller as its parent, the only way I can get navigation items to display in the app (in the view controlled by the View Controller on the right) is by placing them in the nav bar of the Tab Bar Controller scene.
However, this creates various issues, including not being able to create an IBOutlet in my View Controller file for a custom view I drag into the title view slot in the Tab Bar Controller scene. Meanwhile, dragging anything into the navigation bar in the View Controller scene just makes it not appear in the app when it runs.
Question 2: How can I fix this layout so that I can control-drag from navigation items into my View Controller file? Or is everything actually correct, and I'm just trying to force something I shouldn't? (My intention here is to be able to set the custom title view's text in my View Controller code.)
Its obvious, if you want to embed MyViewController to NavigationController then you need to change your second step and need to embed NavigationController to Tab Bar Controller.
Selected MyViewController and used Editor->Embed In->Navigation Controller.
Selected NavigationController Embed with MyViewController and used Editor->Embed In->Tab Bar Controller.
It should look like this.
Note: You need to embed MyViewController to navigationController only if you want to perform push operation on this TabBarItem means with MyViewController other wise simply embed MyViewController to TabBarController no need to embed it with NavigationController.
I have a problem with SWRevealViewController. In my app I have a long chain of UIViewControllers connected to a single UINavigationController. After adding a side menu and setting the "reveal view controller push controller" segue for cells I see only ViewControllers connected with a segue. I can't move between my UIViewControllers in the chain any more. And navigation bar is missing. Is it possible to use a side bar and UINavigationBar at the same time?
I see your image I think you have to add another navigation controller before the C****** S****** View Controller or the view controller you want to go
the reason is that there is no UINavigationController before the C****** S****** View Controller and that's why Navigation bar is hidden and you can't move
The Problem
I'm relatively new to Swift and I'm trying to build an application that makes use of a UITabBarController.
What I'm trying to do is put a different navigation bar (or UINavigationItem) on each of the tabs in the UITabBarController.
For example, I want the UINavigationItem I set, with its bar button items, to appear on MyViewController instead of a back button to the previous view controller, such as shown on the image below.
The current layout on the Storyboard is as follows.
MyViewController on the sidebar:
What I've Tried
Someone suggested that I should embed each UIViewController (e.g. MyViewController) in a Navigation Controller. I've tried this and it doesn't work.
I've also tried to set the Top Bar to "None" in the Attributes tab of the options menu.
Thank you in advance for your help.
Here is how i did it,
UINavigationController -> UITabbarController
And then each "Tab" is in different Storyboard and every storyboard start with a "Navigation Controller". So yes every tab in different navigation controller this how you should do it.
Different storyboards because may be multiple people work on storyboard at same time.
Why TabbarController inside Navigationcontroller ?
I put the "TabbarController" inside "NavigationController" because some of the controllers i want them to be full screen, like hiding the "Tabbar" so for that i push them from main NavigationController.
//Out of context but may help you,
I have created an "Extension" of Navigation Controller to push a view controller on main navigation so that any of the tabbars (which are also inside navigation controllers) can easily use the extension to push any view controller if want to hide the tabbar.
I want to add UITabBarController as root view of my UINavigation controller. The purpose of that is that I want to make similar navigation as Facebook app: Then user select contact on Contacts tab - pushed view with user details doesn't have TabBar.
So, I have navigation controller, tab bar as a root view or it and couple TableViewControllers inside this UITabBarController.
I have two major issues with that:
I can't assign title for navigation bar for root views of tabbar. If I open contact details I have navigation bar title and no tab bar (as I wanted). But if I select Contacts or Favorites - those views have empty navigation bar title. I've tried to set it on viewDidLoad and viewDidApper without any success
Even worse issue. When I press Favorites table view insets are broken. first cell is under navigation bar. First loaded tableview (in my case Contact) displayed correctly. Adjust scroll view insets is YES for both TableViews.
Update:
Solution storyboard (note property "Hide Bottom Bar on the Push" is switched to YES).
I was also struggling with UITabBarController + UINavigationController issue. When UITabBarController was contained by UINavigationController, content insets were acting really weird.
I would suggest to use navigation controllers inside UITabBarController and when next controller is pushed, set 'hidesBottomBarWhenPushed' on that controller to YES.
This would also solve setting navigation bar title, as navigation controller is closer to view controller. You can just use self.navigationItem.
If you leave it to current setup - UITabController contained within UINavigationController, then you need to modify navigationItem on controllers tabBarController (self.tabBarController.navigationItem). Note that best place for it would be in view controllers 'viewWillAppear' for every controller contained within UITabBarController, as they share one navigation item.
When I try to add a UIBarButtonItem to my UIViewController, nothing shows up at run time.
What I did:
I started off with a brand new single view project.
I dragged a UIBarButtonItem into the view controller.
I can now see and customize the item in the storyboard, but when I run it, there is no toolbar.
Note: the Bar Button Item appears as a direct child of View Controller.
How can I get the UIToolbar to appear?
Adding toolbar items as direct children of the UIViewController corresponds to the toolbarItems property of a view controller. The documentation states:
If this view controller is embedded inside a navigation controller
interface, and the navigation controller displays a toolbar, this
property identifies the items to display in that toolbar.
So, you must do the following:
Embed the UIViewController in a UINavigationController (e.g. select the UIViewController in the storyboard, choose Editor > Embed In > Navigation Controller).
Select the UINavigationController and check the box that says Shows Toolbar (this is the similar to calling self.navigationController.toolbarHidden = NO in the view did load method).
Optionally, if you want to restore the behavior where the navigation bar wasn't visible, then uncheck the Shows Navigation Bar property.
An alternative approach is to not use the toolbarItems property, and instead add your own toolbar and maintain it yourself (e.g. add an IBOutlet and interact with it that way).