I am new to iOS development and I have started with IOS 5 directly. I have created a storyboard which consists of a tabview controller as its rootviewcontroller. I have put 2 tabs to it.
I want to deselect/unselect all the tabs initially. How do I do this? I have tried the following
UIView *view = [[UIView alloc]initWithNibName:#"view" bundle:[NSBundle mainBundle]];
[self.tabBarController setSelectedViewController:nil];
[self.tabBarController setSelectedViewController:view];
where I have added a view with identifier "view".
But this didn't work, it gives error:
unrecognized selector sent to instance
I also tried the following
[self.tabBarController.tabBar setSelectedItem:nil];
but it says
'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
I have tried this code in controller for the first tab. I want to do this because I want to put a default view on top of first tab view and hide it once the use is clicked on any of the tabs below.
I use this to clear any selected tabBarItems
[myTabBar setSelectedItem:nil];
Old question. Just for the record, you can't deselect all the Tabs if the Tab Bar is managed by a TabBarController. The method:
[self.tabBar setSelectedItem:nil];
Works only if the Tab Bar is not managed from a Tab Bar Controller. If it is, there's no way to deselect all the tabs, there must be one selected at all time.
This is a little hoakey. But I simply set the tint color in -viewWillAppear to gray when I wanted it to look like there was no selection and then set the tint color back to the "selected" color when I want to show the selection.
// since we cant turn off tabbar selection, change the color to make
// it look like nothing was selected.
self.tabBarController.tabBar.tintColor = [UIColor grayColor];
-----------
// make sure tintcolor is turned on (just in case another module turned it off
self.tabBarController.tabBar.tintColor = self.view.tintColor;
I've found a solution that is probably not the best way to go about it but it worked for me ([self.tabBar setSelectedItem:nil]; didn't). I put my tab view in a parent view (myTabBarViewContainer) and then when I want to deselect my items I call removeFromSuperview on the parent view and re-init it :
[self.myTabBarViewContainer.view removeFromSuperview];
Then re-init it and Voila!
Not very pretty but it works...
You Should need to use UITabBar. Not UITabBarController
deselect or unselect tabbar item swift 3.0
tabbar_Main.selectedItem = nil
Related
I have a UITableView with some Cells.
I don't use NavigationController, so I'd like to use UIModalTransition to Switch from RootController, my TableViewcell, to my DetailView, but want to add a Navigation bar to attribute some actions, like Backbutton.
I don't want to use seguesTransition, I only used XIB File and any Storyboard.
I really don't know how to use the Modal Transition in TableView, anyone know how i can do it ?
Thanks.
have you tried
[self presentModalViewController:yourViewController animated:YES];
then you can set certain styles for transitions in it.
On the other view add a navigationbar and place a backbarbuttonitem and add an action to it to go back to your previous view.
Although why do you want to do it is unclear to me.
if you dont want a navigation controller on the first view, you can just set it to hidden.
self.navigationController.navigationBar.hidden = YES;
and then in the viewDidLoad of other view you can do the reverse i.e
self.navigationController.navigationBar.hidden = NO;
this is quite an easy way of achieving what you want with relatively less amount of code!!
I want to hide the bottom toolbar on a certain screen in my application, and IB seems to have an option for that which seems to preview as working correctly, but when I build and test the application the bottom toolbar is still there.
I know that I can use [self.navigationController setToolbarHidden:YES]; but my question is not how to do it using code, but how to get this to work through Interface Builder.
Here is a screenshot of what I am talking about. See on the right how I have selected Bottom Bar: None - this removes the bottom bar as previewed to the left. If I set it to inferred (instead of None) the bottom bar shows in the IB preview.
How do I get this to work correctly?
You can't set this in Interface Builder. If you notice the header of the section in IB where you can turn on/off these different bars, it says "simulated". These options are only there to help you visualize your UI in IB while designing it. They have absolutely no influence on the running app.
I couldn't do it in storyboard when you just want to hide toolbar in one view controller. If you want to hide it for all, you need to go to the navigation controller, and set the values in the storyboard. But this makes all of your view controllers to hide the toolbars. If you want to hide it for one view controller use this in that view controller:
-(void) viewWillAppear:(BOOL)animated
{
[self.navigationController.toolbar setHidden: YES];
}
-(void) viewWillDisappear:(BOOL)animated
{
[self.navigationController.toolbar setHidden: NO];
}
Enable "Hides Bottom Bar on Push" within the IB in case your ViewController is pushed onto a UINavigationController stack.
This should exactly do what you are asking for. As a bonus, the hiding and showing will be nicely animated by the system.
When I push a view via my app's navigationController, it automatically puts a back button on the left side of the navigationBar. Is there any way I can just remove this? (I want to put my own buttons on the screen that will allow the view to be popped).
From the comments, you can hide the back button for a viewController by using its navigationItem property. (which is the UINavigationItem corresponding to that viewController in the stack of the navigationController. its how you control what shows up on the bar for specific view controllers (see Apple Doc here)).
To answer your question, set the navigationItem's hidesBackButton property to YES. Something like this probably called in your viewControllers viewDidLoad: or similar method.
myViewController.navigationItem.hidesBackButton = YES;
have you try with self.navigationItem.hidesBackButton=YES;?
If I wanted to do it, I'd hide the Navigation bar on push (non animated hide), add a toolbar, and add any custom stuff I want to the toolbar.
on popping the view controller, make sure to unhide the navigation bar. It'll work
I have a couple of views in my iPhone app.
each view shows a "top bar" in blue, I haven't added a "Navigation Bar", simply edited what's on the inspector "View Controller" section and gave it a title. (this section: http://img69.imageshack.us/i/schermata20101001a22014.png/)
Is it possible to change the color of this bar that'a automatically added on top of other View Items? or even to hide it? both In Interface Builder or in Code,
thanks.
I'm not sure how to change the one added automatically, I assume that you'll have to make your own to change things such as the color, which you can do easily with the tint option in the attributes panel.
It's the navigation bar from the UINavigationController. You can do stuff like [self.navigationController setNavigationBarHidden:YES animated:YES] and self.navigationController.navigationBar.tintColor = [UIColor magentaColor].
You should not set the navigationBar.hidden/alpha directly, since those are handled by the UINavigationController. Additionally, UINavigationController may not re-layout your views appropriately.
I have an application with a tab bar and a navigation bar. I push a view controller that is used to show photos, one at a time. It initially shows the bars and forward/back controls; after a delay, these hide, using setNavigationBarHidden:animated: and a custom transform (CGAffineTransformMakeTranslation) on the tab bar. This works, but the view controllers view , which shows the photo, leaps up and down. The same is true if I leave the tab bar out of the equation.
How can I prevent the UINavigationBar from moving my view around? I would like the photo to stay fixed in the screen, with the nav bar dropping down over the top segment of it.
Had this issue and fixed it with a class that inherited from UINavigationController
-(void)viewWillAppear:(BOOL)animated
{
self.navigationBar.translucent = YES;
}
Worked great for me, didn't had to set style to UIBarStyleBlackTranslucent. So it did kept my colors.
[[navigationController navigationBar] setBarStyle:UIBarStyleBlackTranslucent];
[[navigationController navigationBar] setAutoresizesSubviews:NO];
this seemed to do the trick for me!
I know this is an old question, but I accomplished that by disabling 'Autoresize Subviews' in Interface Builder
I haven't been able to find a proper way to handle this except to set the navigationBar style to translucent as in:
theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
Other than creating another navigation bar and adding buttons to them, that's the best (and it seems to be what Apple does as well in it's Photo app)