Deselect or unselect all tabs in tabbar in iOS 5

怎甘沉沦 提交于 2019-11-30 21:23:42

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!