我想我已经完成了这里的功课。
我希望我的应用委托(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/