Setting different Bar title for ViewControllers - ios

I have a viewController with NavigationController and TabController embed in. (TabController is set as initialViewController)
I would like to change the tile of navigation bar, but if I change title of one viewController it is applied to all ViewControllers .
How can I write a code for each ViewController to have different barTitle?
[Navigation Controller as initialViewController]
[![TabBarController as initialViewController][2]][2]

For that you need to embed all your Tabbar's ViewController to NavigationController, So now every viewController having personal navigation and it is easy to set title to individual viewController and set UITabbarController as initial ViewController of storyboard.
So your Structure should be like
TabbarController
|->NavigationController1->ViewConctroller1
|->NavigationController2->ViewConctroller2
|->NavigationController3->ViewConctroller3
|->NavigationController4->ViewConctroller3
Check below image for more references: TabbarController with 3 ViewControllers

I think this is what Nirav is suggesting which is the correct way.
Add as many view controllers you want in tabBarController. Now embedd every view controller into a navigation controlller

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.

Set RootViewController in UIViewController

Currently i working on iOS App and my requirement is to set TabbarController as a root view controller in all the upcoming features ViewController. so anyone can please suggest me how it possible ?
This my TabBarController
and this was Viewcontroller for Edit Profile which is outside viewcontroller means not in mention 5 tabs viewcontroller.so i wanted to to Display in bottom of controller TabbarViewController as a root viewcontroller.
OK, that's simple.
First, you should embed in a UINavigationController to your Middle View Controller.
Then, you can push Edit Table View Controller when press edit button
Here is an overview :
I only add two controller into tabbarController you can add five controllers.

Retain UIViewController in TabBarController

I have created my own custom TabBarController which is subclass of UITabBarController and i override this function :
- (void)setSelectedViewController:(UIViewController *)selectedViewController {
[super setSelectedViewController:selectedViewController];
}
Inside the Tab in TabBarController, let say Tab NO.4, i can push another ViewController. So now in Tab NO.4 have a new ViewController up on it. And now, i can tab on another Tab, let say Tab NO.3. So the problem appear here, when i tab again Tab NO.4, the new ViewController is disappeared, it doesn't retain.
How can i make it retain? Facebook app is one of the example.
For that you have to take saperate navigation controller for each tab.
Suppose you have three tabs you nee to take three navigation controllers.
http://www.appcoda.com/storyboard-tutorial-create-tab-bar-controller-and-web-view/
You can take UINavigationController as a view controller instead of UIViewController in which tab you want to push a new view controller. It will automatically retain that controller after the selection changed. You also can hide navigation bar if not required.
Here is an example:
http://www.raywenderlich.com/50308/storyboards-tutorial-in-ios-7-part-1

Going from NavigationController to TabBarController

So... I've got a ViewController that's being pushed onto a NavigationController. In interface builder I create a separate ViewController and Embed it into a TabBarController and it looks good in Interface Builder.
In my app, I'm trying to go from one of the ViewControllers in my NavigationView to the ViewController in the TabBarController. How would I do this the correct way? I can't just push the view onto the NavigationController, because the tab bar at the bottom won't show up.
Any help would be greatly appreciate.
I believe you're operating with the UINavigationController and UITabBarController in a backwards order to recommended best-practice.
Unless something has changed in the last year or two (which may have happened) the UINavigationController should never have a UITabBarController pushed onto it. If you are using a UITabBarController in your app, it should be the window.rootViewController, and the navigation controller being member of the UITabBarController's viewControllers array.
I'm trying to go from one of the ViewControllers in my NavigationView
to the ViewController in the TabBarController. How would I do this the
correct way?
In that structure, you'd assign your destination view controller as another element of the viewControllers array. Then, in my style, I'd send a NSNotification something like "LaunchOtherViewController" from your first view controller, and thus you have no need for the first view controller to know about the tab bar controller or second view controller. Then have some class that knows about the second view controller receive that notification, and update the selectedIndex of the UITabBarController to that of the second, destination view controller.
Hope that makes sense.
You need to push the TabBarController onto the view. You may need to set the selected view controller of the tab bar, but it's important the tab bar controller be actually pushed onto the navigation stack (or presented modally).

iOS Storyboards - Re-use UIViewController

I've got the following structure setup in my Storyboard.
I've got a TabViewController (circled in red) that shows a UIViewController via one of its tabs by doing a push (circled in blue).
I want to re-use that UIViewController from the TabViewController. I'd like to 'push' it but I don't really have a navigation controller so I may end up displaying it as a modal.
However, I'm not sure how to handle navigation back to the TabViewController since in this case there's no navigation bar. Any suggestions on the best way to handle this?
EDIT
Is there a way to insert a Navigation controller when its displayed directly from the TabViewController?
Why don't you put your view hierarchy like this:
UITabBarController -> UINavigationController -> BlueViewController
This UINavigationController should be put in the viewControllers property of the UITabBarController instance. If you do this, you can push and pop as many view controller as you want and you can also hide the navigation bar if needed.
Cancel button whose action is [self dismissViewControllerAnimated:YES completion:nil];

Resources