gpt4 book ai didi

iphone - 选项卡栏 Controller :shouldSelectViewController: not being called when delegate is set

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

我想我已经完成了这里的功课。

我希望我的应用委托(delegate)成为我的 UITabBarController 的委托(delegate).

使用 IB,我连接了 UITabBarController的委托(delegate)给我的应用委托(delegate)。

App Delegate 头文件是:

@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

我要实现的委托(delegate)方法是:

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
NSLog(@"shouldSelectViewController called.");
// do some stuff with viewController
return YES;
}

我的应用委托(delegate)有一个导出到 UITabBarController这是在 IB 中连接的。当我这样做时:

NSLog(@"tab bar controller delegate is %@", self.tabBarController.delegate);

我得到了一个很好的结果,例如 tab bar controller delegate is <MyAppDelegate: 0x6e86a30> .

我错过了什么?

最佳答案

就写这段代码吧。通常在 viewDidLoad() 中。

self.tabBarController.delegate = self;

如果当前 Controller 是一个 UITabBarController 那么:

self.delegate = self

关于iphone - 选项卡栏 Controller :shouldSelectViewController: not being called when delegate is set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9493663/

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