How to switch to a different UITabBarItem on UIButton touch up inside - iphone

I have a UITabBarController as my MainWindow.xib. I have 3 tab bar items on the tab bar. On the second tab bar item, i have placed a UIButton. When the user taps the button, i want to be able to switch to the first tab bar item and display the view loaded there. How would i do this programmatically?
Thanks

You can use UITabBacController's selectedViewController property if you have a reference to the view controller you want to switch to, or you can use selectedIndex if your tabs have a static order and you know which index to switch to.

Related

How to embed in a viewcontroller without tab bar when the parent is a tab bar viewcontroller?

My current hierarchy is:
Tab bar controller
Navigation controller
A UIViewController
Another UIViewController
It shows tab bars at the second UIViewController (so number 4 in the list). I want to remove that tab bar, but I want to keep the navigation at the top. This is because the first UIViewController (number 3 in the list) holds a tableview, and when a user clicks on a cell it goes to the second UIViewController and I want to keep a back button.
An example is when you open WhatsApp, you have a list of conversations (left side of image). When you click on a conversation, the tab bar buttons at the bottom are gone (right side of image). I can hide them in the second UIViewController, but it causes some glitches. I am sure there is a better solution.
In presented/pushed viewController's viewDidLoad, or in the storyboard, set the view controller's hidesBottomBarWhenPushed to true.

UIViewController in a UITabBarController without tab bar item

So I have this application where I have a view controller (which I want to appear first when the app starts) and a tab bar controller. I also have other navigation bar controllers that are in the tab bar controller. I want to place my view controller on top of the tab bar controller. Making the tab bar controller the parent of the view controller would be better though.
But take note, I do not want a tab bar item to represent the view controller and I want the tab bar to appear along with the view controller. I do not and would not want to use storyboards as much as possible. How can i achieve this?
I guess the simplest solution would be to use a screenshot of your tabBar and put it in your HomeViewController as a button. In this case you could use your HomeViewController as rootViewController and in the button action you set the TabBarController as the rootViewController.
Root = Home + Button
-->
Root = TabBar
Perhaps you need four buttons, if you want the correct tab to be selected.

Remove TabBarItem highlight

I have a UITabBar based application, on one TabBar Button I have a navigation controller. When I move to navigation controller, tab bar highlight option needs to be removed. No tab bar buttons should be selected.
How could I make this possible?
Try to take a look at the "Managing the Finished and Selected Image" task's section of the UITabBarItem docs.
If you want to change tabBar index then use
[self.tabBarController setSelectedIndex:index];
of if you dont want to show selected index then just hide tabBar.

how to add a uitab bar controller with non of the tab get selected?

I have added an UITabBarController. My requirement is to display a view with tab bar controller. but that view is not part of the tab bar items. For example my tab bar contains 3 tabs
contacts
camera
history
Generally if we add tabbar controller contacts will be get selected and that view will be displayed automatically. but i don't want in that way...
i used [tabBarcontroller setSelectedViewController=nil];
i am able to get a tab bat with non of the tab get selected. but when i am trying to select a tab item it's not working.. I think i set the selectedViewController to nil. is there any other way to achieve my requirements...?
please explain your answer clearly.. i am new to iphone app development..
Present a view controller which is not a part of your tab bar controller and put a tab bar image/buttons at the bottom of it which resembles your tab bar. When you receive a button pressed message from within that view controller, show that tab on screen.

Hide TabBar when clicked on one tab Item

I have four tabBarItems. When a user clicks on the first tab item the tab bar should be hidden. The other three tab bars should appear. Is this possible?
Warning up front: this is an unusual handling of tab bars.
If you hook up the UITabBarItem as an IBOutlet, and also hook up the UITabBarController's delegate, then in the method tabBarController:didSelectViewController: you can test to see if the user has tapped the tab bar you're interested in. If so, you can set it's title property to #"" and if it has an image you can set it's image property to nil.
This will look sort of strange though - it will give you a fully functioning tabBarItem, that is basically transparent.
If you really want the tabBarItem to disappear, remove it from the tabBarController, by resetting the tabBarControllers.viewControllers property to an array that does NOT contain the viewController you want to hide.