开发者

UITabbar without controller

开发者 https://www.devze.com 2022-12-24 12:01 出处:网络
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:

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 UITab开发者_运维问答BarItem.

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

So frustrating....thanks!


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.

0

精彩评论

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