tabBar didSelectItem似乎无法正常工作 [英] tabBar didSelectItem seems not to be working

查看:65
本文介绍了tabBar didSelectItem似乎无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的头文件中,我有这个:

In my header file I have this:

@interface TabBarController : UIViewController <UIApplicationDelegate, UITabBarDelegate, UITabBarControllerDelegate>{

    IBOutlet UITabBarController *tabBarController;

}

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

在我的主文件中,我有这个:

In my main file I have this:

@synthesize tabBarController;

-(void)viewDidLoad{
    [super viewDidLoad];
    self.tabBarController.delegate = self;
    self.view = tabBarController.view;
}

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    NSLog(@"rawr"); 
}

- (void)viewDidUnload {
    [super viewDidUnload];
}

- (void)dealloc {
    [tabBarController release];
    [super dealloc];
}


@end

我已经在接口构建器中将我的tabbarcontroller作为代理连接到我的文件的所有者,但是它仍然从不调用didSelectItem方法.

I have already connected my tabbarcontroller as a delegate to my file's owner in interface builder, but it still never calls the didSelectItem method.

这里有什么我想念的吗?

Is there anything that I'm missing here?

我已经添加了tabBarController.delegate = self;,但仍然无法正常工作.

I have already added tabBarController.delegate = self; and it still does not work.

推荐答案

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;

此方法是UITabBar的委托方法,而不是UITabBarController的委托方法,所以

This method is a delegate method for UITabBar, not UITabBarController, so

self.tabBarController.delegate = self;

不起作用.

标签栏控制器具有其自己的UITabBar,但是不允许更改由标签栏控制器管理的标签栏的委托,因此只需尝试使用UITabBarControllerDelegate方法,如下所示:

Tab bar controller has its own UITabBar, but changing the delegate of a tab bar managed by a tab bar controller is not allowed, so just try UITabBarControllerDelegate method like this:

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

这篇关于tabBar didSelectItem似乎无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆