How do you change views from a Tab Bar Controller - ios

I am developing an app that consists of a Tab Bar Controller that points to 3 view controllers (all with tabs). In one of these tab views I've made a button and I want it to open a new view (without a tab at the bottom). This new view would need a navigation bar with a back button to return to the previous view, so I was thinking I need to create a navigation controller?
Essentially this is what I'm trying to do (I apologize for the poorly drawn diagram).
How can I get this new view (entirely independent of the tab bar controller) to display programatically? Would this require a navigation controller?

You are describing a presented view controller. Call presentViewController:animated:completion:.
I very frequently do this with a navigation bar and a Back or Done button, just as you describe. But it's not a navigation controller or navigation interface; it's just a convenient way of showing the user how to get back.
For example, this is a presented view in one of my apps. The top is a navigation bar, and the cancel button gets us back (call dismissViewController...). The rest is a scrolling view (a UICollectionView) of buttons.

[myTabBar setSelectedIndex:1]
You may have to access the tabBar like self.tabBarController so… [self.tabBarController setSelectedIndex:1];
1 is index 1 in the tabbar's stack (this is like tapping a tabBar button manually)

Related

Navigation Bar and navigation items not visible on runtime

I don't understand why SignIn and SignUp navigation Bar and the back buttons are not visible even when embedding both of these views in the navigation controllers.
Is there anything else we have to do in code. All top bars are inferred in this case and I haven't touched the visibility of any.
There is no back button because there is nowhere to go back to. Your sign up and sign in view controllers are the root view controllers of their respective navigation controllers.
There is no visible title because what you are looking at is the navigation item of the tab bar controller, which has no title.
Your architecture posits a navigation controller insider a navigation controller, which is illegal:
nav controller -> tab bar controller -> nav controller
You can't do that.
Also you can't put a tab bar controller inside a navigation controller. A navigation interface inside a tabbed interface is fine (as illustrate in Apple's own docs: https://developer.apple.com/documentation/uikit/uinavigationcontroller). The reverse, a tabbed interface inside a navigation interface, is not.
The simplest solution is to eliminate the first navigation controller completely, as there is no need for it (you are not pushing anything onto it beyond its root view controller).
IN SIMPLE TERMS
Logically, your Tabbar should not be embedded in a UINavigation Controller. Instead, delete the NavigationController and make the Tabbar the root Viewcontroller then embed each UIViewcontroller in a separate Navigation controller

iOS tab bar controller adding a navigation button at the top of the controller

So I have a UITabBarController and it has three buttons on the bottom in my iOS app. I want to add another set of buttons at the top but not quite sure on how to do this. I tried adding a UINavigationBar and a navigation button, and adding a view in to it, adding just the buttons, ect.... but to no avail. It won't let me add anything to the UITabBarController. Is there a way to do this?
Thank you very much.
the simplest way to that is to creat 3 buttons side by side and set their frame the way they divide the top of screen to 3 equals. it means u can create a tab bar with buttons manually.
but there's another way. i think this answer would help u
Positioning UITabBar at the top
To use the navigation bar you need a navigation controller. Now depending on your needs your tab bar controller should be inside a navigation controller or the other way around. If you want to be able to navigate away from the tab bar controller (have a screen without the tab bar) you should embed your tab bar controller into a navigation controller. If you only need the navigation bar for some tabs of the tab bar controller or you still want the tab bar to be visible all the time you should embed all (or just the ones than need a navigation bar) your root view controllers for each tab in navigation controllers. Finally if you do not need the navigation behaviour you could just put a regular view in the view controller that needs the bar at the top and some buttons in it and make them look the way you want.
You can embed a view controller in a navigation controller in a storyboard by selecting the view controller and the going to Edit->Embed in->Navigation controller.
Select the Any Tabbar ViewController then above the Menu -> Editor -> Embed In -> Navigation Controller its select, if you get the Navigation Controller then if you add the Navigation Button at Top of the ViewController, example :

Pushing view controller onto view control in tab controller

So I have a tab bar controller that holds a search view and a profile view. When I click on one of the cells in the search view I want to go to another view controller, still have my tab s on the bottom and maintain the user's ability to click a back button to go back to the main view.
I've achieved the back button part, but I haven't achieved the maintaing tabs part.
This is what I've tried -
-(void)displayCardController{
if(self.userProfile == nil){
[self.tabBarController setViewControllers:#[self.searchViewController, self.loginViewController]];
[self.searchViewController.navigationController pushViewController:self.searchViewController.detailController animated:YES];
} else {
[self.tabBarController setViewControllers:#[self.searchViewController, self.profileViewController]];
[self.searchViewController.navigationController pushViewController:self.searchViewController.detailController animated:YES];
}
}
The idea is - set the tab to have my controllers, and then push what I want to be on top. That doesn't work.
How do I achieve this?
It looks like the problem is that your first tab controller child, self.searchViewController, has a navigation controller. If you want to be able to push onto this controller while still staying inside the tab controller, you need the search view controller (or whatever is the first tab controller child) to be a navigation controller.
Note that its navigation bar can be hidden, so it won't look like a navigation controller, but when you push, you can show the nav bar and so give the user a clear way to get back.
Alternatively, use a different interface. What I do, for example, when I have two tabs and one of them needs to change temporarily, on the iPhone, is use a presented view controller: instead of push/pop, I use use present/dismiss. On the iPhone, this hides the tab bar, but we return to the same place when we're done so the interface is clear. (On the iPad, a presented view inside a tab bar controller does not have to hide the tab bar.)

Tab bar disappears when trying to go back from new view

I am very new to Xcode and have encountered an issue with my app. I am trying to create a tab bar app. On one of the tabs I have a button that brings the user to a different ViewController. I want to have it so the user can select a button that would return them to the tab that had the button. I tried to set up an action from the button to the previous view (the tabbed screen), however the tab bar disappears. I hope this is makes sense.
Here is a link to a screenshot...
Easiest way to do this is to place a UINavigationController as the root view controller of the TabBarController. You can do this in storyboard by simply ctrl+dragging from the tabbar controller to the navigation controller and adding it as a relationship.
Here's an example using storyboards:
The next step is to set the third controller (in this case the table view controller) to your player view controller class.
Then, you can use the default back button and animation that comes with the navigation controller. If you prefer to hide the navigation bar at the top of the screen, then you can use your custom back button to call
[self.navigationController popViewControllerAnimated:YES];
You can also choose custom animations / segues, etc. but using a navigation controller to help you navigate screens is probably the simplest approach.

Hidden UINavigationController inside UITabBarController

I have an application with 5 UIViewControllers each inside a corresponding UINavigationController, all tucked inside a UITabBarController that displays 5 tabs at the bottom of the screen.
I want to display another UIViewController (inside a UINavigationController) when a dialog button is pressed.
This view should only be loaded and unloaded programatically; i.e. it should not appear in the tab bar. However, I want the tab bar to be visible always.
If I add the [UINavigationController view] to [self window] the UITabBar is covered. If I add it to any other layer, the UINavigationController adds on the compensation it has for the status bar so appears further down than expected.
A solution would be to have the 6th UINavigationController added to the UITabBar with the others, but with its tabBarItem hidden. Then I can show it and hide it using the tabBars selectedIndex property.
Accessing the tabBarItem through the UIViewController shows no obvious way of doing this.
#wisequark, I think you completely misunderstood and you have almost rewritten the architecture of my application. However I have a separate navigation controller for each view as they are mutually exclusive and there is no concept of "drilling down".
#Kendall, This is what I expect I will have to do - have the modal view appear with a hide button to bring back the normal interface. But it would be nice to keep the tab bar always visible, so I was just wondering if anyone knew of a way.
It sounds as though you have a mess on your hands. A UINavigationController is a distinct object that is very different from a UITabBarController. In general, your application should have a tab controller, one of who's tab's loads a UINavigationController which in turn loads it's views - not that both maintain management over the different views. It is also improper to refer to the display of a UIViewController as such an object doesn't have a visual representation. In the case of a UINavigationController, the navigation controller object is responsible for displaying a navigation bar and a table view (in the most common case) and for managing the display of all the views in the navigation hierarchy. It itself has no corresponding representation on screen. Similarly, a UITabBarController presents a tab bar and is responsible for the loading and unloading of the views and/or view controllers attached to the tab buttons. If we were to present this as an image, it would look something like this -
alt text http://img.skitch.com/20081112-2sqp7q4wafa34te1ga337u4k8.png
Well, it sounds like what you really want to do is present a modal view with the tab bar still visible. You could add your view as a subview of the tab bar controller's view. The tab bar's view is, oddly enough, not the tab bar itself but rather a view containing the tab bar and the selected item's view.
Alternatively, you could try calling presentModalViewController:animated: with the selected tab (i.e. [tabBarController.selectedViewController presentModalViewController:animated:]) as the receiver instead of the tab bar. I seem to recall doing this once (quite by accident) and the tab bar remained visible.
One more thought: since each of your five view controllers is a UINavigationController, you could always pushViewController:animated: onto the selected view controller, then hide the back button. Your view will just appear without animation. But you'll need to remember to pop your view controller off the stack whenever the user switches to another tab. That might take a bit more work.
The best idea I could think of would be to either push a modal navigation controller for your view (which would hide the tab bar which you do not want), or to get the tab bar controller current selected view controller (really your navigation controller for a tab) and push your new view controller on there - and then pop that view when another tab is selected with a tab bar delegate.
It seems wierd to me to push the view onto random tabs though, if the view is created from a dialog that is modal, I don't see why the view itself should not also be modal and hide tabs.

Resources