1

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!

4

1 回答 1

2

似乎- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item 在用户拿起手指而不是在那之前被调用。

我知道您不想使用 UITabBarController 但它具有您想要的所有功能。为什么不想使用控制器?

应该工作的 UITabBarController 委托方法:

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

然后你可以在那里返回 NO,并且选择不会改变。

于 2010-03-25T16:03:31.677 回答