Set same navigation bar for UITabBarController child view controllers? - ios

I have a storyboard that looks like this:
Structure:
UINavigationController -> UIViewController
UITabBarController |
UINavigationController -> UIViewController
I would like to apply the same navigation bar for both of the child view controllers of the UITabBarController.
I read on multiple pages in the internet that Apple strictly recommends not to embed a UITabBarController directly within a UINavigationController.
However, I have no idea how to get the same status bar for all of the underlaying controllers (I want all buttons to work the same on all controllers).
As said in the comments, I want both UINavigationControllers to look the same, I want them to navigate through the same controllers and I want to add custom buttons that function the same in every UINavigationController.

Here is a good example of what you wat
basically you can use
UINavigationBar.appearance()
To have the same UI for your navigation bar (or other elements) throughout the aplicaiton.

Related

Different navigation item for each view in tab bar controller

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.

TabBarController with NavigationController

I have a TabBarController with 3 tabs set up in my storyboard. I want to have each tab have its own navigation controller. However, I don't want to embed each one in a nav controller, cluttering the storyboard and then having to style the navigation each time. Is there any way to do this programatically? In other words each time a tab is tapped, the resulting view controller will be set as the root of one existing navigation controller?
I don't think that there is a way to 'set' the rootViewController every time, but you can do 3 navigationControllers in your storyBoard and build a subclass of UINavigationController. That way you don't have to set it every time. Subclassing UINavigationController has become possible since iOS 6 (See documentation):
The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and makes it easier for the user to navigate that content. You generally use this class as-is but in iOS 6 and later you may subclass to customize the class behavior.

How to use same UINavigationBar for all UIViewControllers

In my app, I have to show same NavigationBar for all UIViewControllers. This NavigationBar has three buttons and these three buttons which will be act as TabBar functionality, that is each tab has its own stack cycle. I have created custom view for NavigationBar with three buttons, but after adding this custom view to HomeViewController, I have to manually add this custom view for all other view controllers. I don't want to do this.
Is there any simple method to achieve this?
There are a couple of ideas that come to mind. First of all, you could use view controller containment and actually have 1 controller that implements your custom nav bar, and then swap out the contained controller as necessary.
If that's not feasible, you can simply use inheritance and have all your custom controllers inherit from a controller that has the nav bar in place.
Another option could be to write your own UINavigationController subclass. I'm not certain if you can override the UNavigationItem behavior, but if you can, you can just just do that -- instead of the UINavigationController taking its child's UINavigationItem to update its own UINavigationBar, the UINavigationBar perhaps just stays the same, like you're expecting/hoping.

How to change view with UITabBar (without using UITabBarController or addSubview)?

I've tried a lot to get this done.I don't want want to use addsubview or uitabbarcontroller. I want to switch the view when I tap on different tabs and tabbar should stay there. Thanks a lot in advance.I m a newbie.I want to use uitabbar not uitabbarcontroller.
A simple approach would be to wrap the view controllers you are inserting in UITabBarController in a UINavigationController then you can simply push your new view to that UINavigationController and the tab bar would be always visible!
For more details refer Apple Docs
Edit:
If you don't want to use UITabBarController then you need to do 2 things:
Add the tab bar View to UIWindow that way it would be always visible.
Scale/adjust the views in your view controllers to leave space for the tab bar

UINavigation Controller Before Tab Bar Controller and After Tab Bar Controller?

I have an application which starts with UINavigationController and contains a UITableViewController. In the UITableViewController on an event Tab Bar Controller is pushed which contains 5 View Controller each with one UINavigation Controller.
The NavigationController inside the Tab Bar is coming beneath the UINavigationController which is before the Tab bar.
Hierarchy of the application:
UINavigationController >
UITableViewController >
Tab Bar >
5 View Controllers each with UINavigationController >
View Controllers inside each ViewController above
I want the respective UINavigationController , Should replace the above UINavigationController ..
Apple's HIG recommends that you use the TabBarController on App level, I wouldn't risk to abuse it like that.
In general, use a tab bar to organize information at the app level. A tab bar is well suited for use in the main app view because it’s a good way to flatten your information hierarchy and provide access to several peer information categories or modes at one time.
https://developer.apple.com/Library/ios/documentation/UserExperience/Conceptual/MobileHIG/Bars.html#//apple_ref/doc/uid/TP40006556-CH12-SW52

Resources