i am facing the problem with the tab bar,when i clicked on navigation bar button,the tab bar button is should be unselected,i tried but failed to do that.can any one help me to resolve the issue.
-
not clear what you are asking, add some more details. – rishi Feb 06 '15 at 08:34
-
@rishi : in one view both navigation bar and tabor is there.fist time in tabbar one button is selected,now i clicked on navigation bar button,now i want to unselect the tabbar button – Mahesh Reddy Feb 06 '15 at 09:00
-
Can you add some screen shot showing your exact problem. – rishi Feb 06 '15 at 09:10
-
how to put the sreenshot,i am unable to do that here – Mahesh Reddy Feb 06 '15 at 10:25
1 Answers
If i understood your needs, I guess what you want to do is to select no item at all in your tabbar.
So doing :
[tabBar setSelectedItem:nil];
should be what you need.
That is only if your tabBar is not handled by a UItabBarController. Else you'll get the following exception.
Directly modifying a tab bar managed by a tab bar controller is not allowed.
This behavior is unfortunately logical if you read the doc on the tabBar property of a UItabBarController : UITabBarController documentation - tabBar
You should never attempt to manipulate the UITabBar object itself stored in this property. If you attempt to do so, the tab bar view throws an exception. To configure the items for your tab bar interface, you should instead assign one or more custom view controllers to the viewControllers property. The tab bar collects the needed tab bar items from the view controllers you specify.
And reading through this page you'll see that UITabBarController gives you no means of selecting an item other than the ones on your tabBar (except the moreNavigationController UITabBarController documentation - moreNavigationController )
EDIT : If you do want to keep your tabBar shown, you can trick the users and make them believe the tab is unselected by applying the "unselected style" to the selected tab. This question should give you everything you need to do that : How to change inactive icon/text color on tab bar?
-
but i am using the tabview controller,so how can i use [tabbar selecteditems=nil]; – Mahesh Reddy Feb 06 '15 at 10:20
-
From the doc, you can't. All you can do is "hide" the fact that it is selected by applying the unselected style of your item to it's selected state. – lataupe Feb 06 '15 at 10:35
-
self.tabBarController.selectedIndex=2; this is working but,selecting the 3 tab,but i don't want to select even one also,i tried with nil but first tabor was selected – Mahesh Reddy Feb 06 '15 at 10:35
-
The fact that tab 3 is selected when you do `self.tabBarController.selectedIndex=2` is normal as the indexes start at 0 so selecting index 0 will show the first tab, index1 will show the second tab, index 2 will show the 3rd tab and so on. – lataupe Feb 06 '15 at 10:43
-
yes i know that,but how to resolve my issue i dont want to select any tab – Mahesh Reddy Feb 06 '15 at 11:25
-
As I told you, Apple doc says you can't. As you should not be displaying the tabBar if none of it's tab is selected. Maybe the view opened from a tap on a button from your navigation bar should not display the tabBar at all since it's a view that is not related to your tabBar. – lataupe Feb 06 '15 at 12:44