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

标签 iphone ios cocoa-touch delegates uitabbarcontroller

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

我希望我的应用委托(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/

相关文章:

iphone - 从图像中检索 RGBA 值

iphone - iPod Touch 第二代 - 固件

ios - Facebook 导入详细信息 ios

iphone - 为 UIWebView 和 UITextView 添加阴影

ios - Xcode - 如何修复 'NSUnknownKeyException',原因 : … this class is not key value coding-compliant for the key X"error?

objective-c - 从 UIPanGestureRecognizer 获取原始触摸位置

iphone - 意外的 UITableViewSeparatorView 版本导致应用程序启动时崩溃

iphone - 如何将文件保存到文档文件夹中?

ios - BLE 设备应该在不扫描的情况下连接

ios - 问题 - DBAccess ORM 使用 swift 声明 bool 类型创建表