gpt4 book ai didi

iphone - tabBar didSelectItem 似乎不起作用

转载 作者:可可西里 更新时间:2023-11-01 03:27:01 24 4
gpt4 key购买 nike

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

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

IBOutlet UITabBarController *tabBarController;

}

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

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

@end

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

@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 作为委托(delegate)连接到我的文件所有者,但它仍然没有调用 didSelectItem 方法。

这里有什么我遗漏的吗?

我已经添加了 tabBarController.delegate = self; 但它仍然不起作用。

最佳答案

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

该方法是UITabBar的委托(delegate)方法,不是UITabBarController,所以

self.tabBarController.delegate = self;

将不起作用。

标签栏 Controller 有自己的 UITabBar,但不允许更改由标签栏 Controller 管理的标签栏的委托(delegate),所以只需尝试 UITabBarControllerDelegate 方法,如下所示:

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

关于iphone - tabBar didSelectItem 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10946058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com