views:

597

answers:

1

Hello.

I have a simple app where the only view controller has an outlet to a UITabBar. It also implements UITabBarDelegate and is set as the delegate for the UITabBar:

@interface TheMainViewController : UIViewController <UITabBarDelegate>
{
      IBOutlet UITabBar *theTabBar;
}

I implemented the following method Which gets called whenever any of my 4 UITabBarItems get tapped. I tried just doing something really simple:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
      tabBar.selectedItem = [tabBar.items objectAtIndex:0];
      return;
}

In theory, it should always stay selected on my first tab and it works perfectly when I just tap any UITabBarItem (nothing happens, the first one always stays selected). But when I touch a UITabBarItem and hold it (not taking my finger off) the selection changes anyway ! Debugging, everything gets called properly.

It's like changing the selectedItem property doesn't have any effect is the user still has the item "down" (with his finger on it).

What would be a good workaround? I tried overloading UITabBar and messing with touchesBegan and touchesEnd but they don't even get called. Same with UITabBarItem.

Oh and please don't suggest using a UITabBarController as it is not flexible enough for my application.

So frustrating....thanks!

A: 

It seems like - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item gets called when the user takes his finger of and not before that.

I know you don't want to use an UITabBarController but that has all the functionality you want here. Why don't you want to use a controller?

UITabBarController delegate method that should work:

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

Then you can return NO in there, and the selection won't change.

Rengers
Well basically I already have a whole bunch of other views that gets animated depending on the status of the tabbar (more than slide in and out). Also, my tabbar is not at the bottom like the controller does it.Switching to a controller would require a major refactor which I want to avoid.As for you other comment, when you click and hold a tabbaritem, the "didselectitem" function gets called after a small delay even though the actual item gets highlighted only when you release.
Etienne