I'm creating a tab bar application using the built-in tab bar app template in Xcode. I have 4 tabs, one of which is a mapView. For a few of the view controllers my code programmatically sets the selected index of the tab bar depending on the user actions. For the mapView view controller I have a method that presents a modal view when the user taps on a selected annotation. The modal view has some information about that selected annotation. I can dismiss the modal view controller and return to the mapView correctly.
My problem is that I would like to put a 'home' button on the modal view controller that should dismiss the modal view and take the user to 0 index on the tab bar (AKA home). The mapView is index 3.
I cannot do a [self.tab setSelectedIndex:0] from the modal view attached to the home button - it doesn't work. Perhaps I'm overthinking this. Can anyone offer a solution / hint? I greatly appreciate it! Thanks.
When you present a modal view controller from one of the tabs, the tab bar controller instance becomes the parentViewController of the modal view controller. You can use this property to call the tab bar controller methods.
[(UITabBarController *)self.parentViewController setSelectedIndex:0];
Related
I have a tab bar controller.
From one of the views i want to goto another view via a button, which i have done.
Once on that page i want to go back using the navigation bar.
This is the problem.
How do i get it to go back to the tab bar controller page?
Thanks
Mat
You can arrange your view controllers as follows:
Tab bar controller
Navigation Controller
View Controller 1 - button to go View Controller 2 using segue
View Controller 2
So, View Controller 2 will have a back button to go to its previous view controller.
I want to add a view controller over navigation view controller in a tab bar application which covers the full screen.
I have crated a view controller (enterPin) and added over the current navigationview controller in a tab bar application.
[self.view addSubview: enterPin.view];
but bottom bar, navigation controller and status bar is not hidding and comes over enterPin view controller. If we hide bottom bar, navigationcontroller and status bar it give white screen at back.
I want the view controller (enterPin) should appear over the navigationview controller (self.view).
Use modal view controller: Tutorial and documentation. Does exactly what you are asking for.
This is very normal behavior. 95% of the time the developer would not want the UINavigationBar to be covered by another view. You have a few options.
Use a modal view controller to prevent the user form interacting with other controls.
Animate the UINavigationBar out or disable it in some way.
Consider making the "Enter PIN" screen something the user sees when they first launch the application.
I have a navigation controller and a tab bar where I have buttons for multiple options. When a button is ever pressed it pushes its respective viewcontroller in navigation controller. That's fine, but when I again press the button in tab bar after loading any other suboption viewcontroller in navigation controller, it shows blank screen instead of that "options screen" which it shows when I touch it first time.
I am using this code:
[self.navigationController pushViewController:accountOptions animated:NO];
You're pushing same view controller twice without ever poping it from navigation controller.
You can either pop view controller when switching to another one or push view controllers once on navigation controller in tab bar and be done with it.
I have an application with a Tab Bar Controller that has three tabs.
In tab 1 there is a view (view1) with a button that when clicked transitions the user to a new view (view2) still within tab 1. However when this new view (view2) is loaded it covers my tab bar controller.
What is the best approach for me to take to still display tab bar controller as well as keep tab 1 highlighted?
How are you performing your "transition" to view2 from view1?
One solution is to use a UINavigationController as the root view controller for tab1, so view1 can display view2 by pushing it on the navigation controller. Alternatively, have view1 display view2 modally.
Either way should not cover your tab bar, and tab1 will still be selected (highlighted).
I think you are pushing the view as modal view if this is the case then the view will definitely cover your tab bar the other way to do this is push the view controller and this will not hide your tab bar.
Try to do it like:
[[self navigationController] pushViewController:viewContObject animated:YES];
Hope this helps,
Thanks,
Madhup
Let's have an example.
In application I have a tab bar controller.
Tab bar has two items dynamically - two view controllers.
User can select any of tab.
Suppose user selects first tab.
First view controller is already loaded.
Now he clicks on a button of First view controller.
From First View controller -> Second View controller is pushed.
Now when user taps on tab bar first item
second view is popped out.
This is done through by default by tab bar controller.
Now, If I want to check following condition
if(tab bar first item-view controller has first view controller view)
then perform this
if(tab bar first item-view controller has second view controller view)
then perform this
How to implement this logic?
If you are using a UITabBarController, you can use its selectedViewController property to know what kind of view controller is on the screen, so if you have two subclasses of view controller FirstViewController and SecondViewController you can say
if([[tabBarController.selectedVIewController isKindOfClass:[FirstViewController class]])
//... do something
else ...