Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deselect or unselect all tabs in tabbar in iOS 5

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.

like image 939
Nik Avatar asked Mar 27 '12 10:03

Nik


2 Answers

I use this to clear any selected tabBarItems

[myTabBar setSelectedItem:nil];
like image 138
HurkNburkS Avatar answered Sep 19 '22 18:09

HurkNburkS


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.

like image 38
tomidelucca Avatar answered Sep 19 '22 18:09

tomidelucca