views:

129

answers:

3

Hi,

When a user wants to choose a certain UITabBar item, I want first to check if he can choose it. And if he cannot, then show an alert.

There is a delegate method that is being raised when a user chooses a certain item, but it doesn't work when an item is disabled.

What is the best way to achieve this?

Thanks.

A: 

Why is the button disabled? Could you not just check if they have access to the button every time and not disable the button?

Roger
I could but it won't be effective - I have those values changing very often. So it would be much more effective to check only when user chooses a certain item.
Ilya
Right but why not just run the check if they have access when they choose the item on the toolbar? Perhaps I am missing your issue.
Roger
+1  A: 

This is not good UI design practice. If a button is disabled it should not respond at all to user interaction. If it isn't disabled it should do something. The only case where it's justified to have a non-disabled button that displays an error/warning rather than performing the desired action is if it can only be determined at the last moment that the action is impossible to perform.

U62
A: 

You'll need to use the delegate method from UITabBarControllerDelegate:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

In that method, make your check to see which the user tried to select, by looking at the UITabBarController's selectedIndex. Alternatively, you can get a reference to the UITabBar itself and inspect its properties:

UITabBar* tabBar = [tabBarController.view viewWithKindOfClass:[UITabBar class]];

If you don't want the tab to be selectable, than fire your alert and assign an integer tabBarController.selectedIndex to change it away from this tab.

Caveat: as the poster above indicates, this is not a UI design practice consistent with other iPhone apps.

Glenn Barnett