make tabbar button as unselected when clicked on the navigation bar button - ios

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.

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?

Related

Swift: how to make tab view controller button not show?

Ok, I have all my view controllers managed by a tab bar controller, and obviously when you connect in the storyboard the relationship between the controller and the Vcs as "view controller" a button appears on the tab bar. These are then accessible via the tab bar controller.
My problem is I need to have one VC be the in view controller array but NOT BE SHOWN IN A BUTTON on the tab bar. It should not be accessible to the user, but I need to be able to switch to that VC in code with selectedIndex
I do not know how to do this. I have tried disabling the button and doing
self.tabBar.items?[3].accessibilityElementsHidden = true
But the button is still there on the tab bar. How can I have the VC in the array of the tab bar controller but not shown in a button?
This is not possible using the UITabBarController as is.
Not 100% sure on why you need to have a VC in that array but never visible on the bar, consider subclassing UITabBarController if thats the case.
Changes to the viewControllers or items property of a UITabBarController will encourage iOS to reload the Component and hence why you are seeing the VC in the TabBar.

View controller problems with old navigation bar and tab bar controller

I have a view controller which was attached to a navigation controller at one point in time. it is still showing some ghost of the navigation bar? It is also showing the Tab Bar but there is not tab bar item shown on it?
any ideas how to fix this, or is it a delete and remake?
Its either the alpha of the rootVC or you have. tab bar controller on the second one. Check your identity inspector on both views

iOS Swift: Incorrect Navigation Bar Appearing

The incorrect navigation bar is appearing on my Table View Controller screen (see Storyboard Below).
I would like what's displayed on the storyboard to be my navigation bar (i.e. with "Main Feed" title and Sign Out button on the top right). However, this is what I'm actually getting -
There are two issues here: 1) The incorrect navigation bar is displaying (this one has a login back button); 2) the first few table view cells are placed underneath the nav bar vs. under it.
This happened after I embedded the Table View controller in the Tab Bar Controller. I want a bottom tab bar in the main portion of my application hence the reason why I added the Tab Bar Controller. Any suggestions on how to fix this? Rather than using the Tab Bar Controller in storyboard, is there a way to do this programatically? Thanks!
The navigation bar that you are seeing on top of the stack is the navigation bar from the UITabBarController itself, that is why you are seeing the back button show "login". There's a few ways to work around this, programmatically:
When you initialize the UITabBarController, set it's navigationController's navigation bar property to "hidden"
Go through each view controller form the beginning of your app up to where you first see this problem and in the "init" method of the viewController you are testing, set the navigationbar to hidden. Something like, self.navigationController?.navigationBar.hidden = true;
This is how you can "debug" this issue, but it's going to take some tweaking to get it right.

How to Add a Bar Button Item on a Disappeared Navigation Bar using Storyboard?

I want to add a bar button item on the navigation bar. (Say View 1 here.) The view that will segue to View 1 is embedded in a navigation controller.
However, the navigation bar is not showing in this view.
If I use attribute inspector to add a opaque/ translucent navigation bar, there will be a navigation bar in View 1. But if I drag in a bar button item, it cannot be shown in the storyboard. Though the bar button is in the document outline, it cannot be shown on the storyboard. Also, if I run the application, it is not on the screen.
When running the application in the simulator, View 1 will have a navigation bar on the top of it, since I use "Show" rather than "Show Details" to show View 1. I tried to embed View 1 in a navigation controller again, but it won't help much.
Can anyone tell me how to add a bar button in this situation using storyboard? And why the navigation bar is missing from the storyboard?
Thanks in advance.
I figure it out by myself.
Drag a Navigation Item from the object list, and then add bar button item to it.
Thanks to rdelmar for his idea, though drag out a navigation bar won't work in the way I thought it should work.
In my situation, View 1 is a table view. Drag a navigation bar to the view will cause it to be the header view for the table, rather than a navigation bar I had expected. Then there will be two navigation bar in the view when I run the application.
Of course we can drag out a navigation bar and add a button to it, it might work different with your expectation. As I had said, it might leads to a view which contains two navigation bars.
You can fix this by drag out the Navigation Item (contains the bar button you had added) inside the Navigation Bar out. In my situation, I drag it out and put it the same level with the table view inside the document outline. Then it won't become the header view for the table view.
After that, we can just delete the navigation bar from the document outline.
I have no idea why the navigation bar disappears in my storyboard. If anyone has some idea for this, please let me know.
It sounds like you're adding the navigation bar by using the Simulated Metrics. If so, this doesn't add one at run time, it's only for layout purposes in IB. You should drag out a navigation bar from the objects list, and add your button to it.

iOS tab bar issue

In my app i'v UITabbarController as rootviewController with 3 tabs on it, each tab has its own UINavigationController.On the first tab i'v attached a UIViewController that hides tab bar and navigation bar, by click on a button user can go to next screen that will show tab bar as well as navigation bar.Now the problem is when i click on first tab on this view controller (which is already selected by default) it takes me on previous view controller and i want it should stay on the same screen.How to achieve this?
Edit: I dont want to disable bar item at index 0 as this turns it into UIControlStateDisabled which make it different looks from others.
Is there any way to set image for UIControlStateDisabled for tab bar item?
Any help or suggestion would be appreciated.
Try this may be helpfull...
[[[[self.tabBarController tabBar]items]objectAtIndex:1]setEnabled:FALSE];
set "objectAtIndex" that you want..

Resources