开发者

How to disable all tab bar items?

开发者 https://www.devze.com 2022-12-22 07:22 出处:网络
I\'m developing with the iPhone 3.1.3 SDK against an iPhone 3GS with the 3.1.3 OS.My app has a tab bar with seven items of which only two contain something meaningful.So for the remaining items, I un-

I'm developing with the iPhone 3.1.3 SDK against an iPhone 3GS with the 3.1.3 OS. My app has a tab bar with seven items of which only two contain something meaningful. So for the remaining items, I un-checked the "Enabled" box in the "Tab Bar Item" attributes (first page, "Bar Item" section).

That works fine for the two visible tab开发者_Python百科 bar items that are disabled - can't click on them. The remaining three, however, are still enabled in the "More"-table when clicking on the "More" tab bar item at the very right - I get their (empty) table view. It seems to me that this is a bug - since these items are not enabled, they shouldn't be clickable, even in the "More"-table. This happens both in the emulator in debug mode and on my iPhone in release mode.

So how can I disable the tab bar items in the "More"-table?


Hmm. This is almost certainly a bug. I would encourage you to file it as one; I certainly will. I tried to come up with a sample app to test this and I confirmed the behavior you’re seeing. Interestingly enough, in the UITabBarControllerDelegate protocol, there is this method:

- (BOOL)tabBarController:(UITabBarController *)tabBarController 
shouldSelectViewController:(UIViewController *)viewController

But that method isn’t called when you select a view controller from the “More” tab bar item. For now, the only way I can see this working is if you remove view controllers that would appear in the “More” view controller, therefore making them impossible to select by virtue of not being present.


I can't seem to get tabBarController:shouldSelectViewController: to trigger, but this works:

for(UITabBarItem *item in self.tabBar.items)
    item.enabled = false;

This might not be what you want, though, 'cause it disables even the "More" item.


You should implement protocol "UITabBarControllerDelegate" and set as delegate to the tabBarController. It works very well!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号