我的 UITabBarController 的 didSelectViewController 方法没有被调用?
这是我的 app-delegate.m 的代码存根——它永远不会被调用。
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSLog(@"%s", __FUNCTION__);
}
它在此 app-delegate.h 中定义
@interface OrioleAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
Here is my code stub for my app-delegate.m -- it never gets called.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSLog(@"%s", __FUNCTION__);
}
It is defined in this app-delegate.h
@interface OrioleAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否在
UITabBarController
和应用程序委托之间建立了连接?Did you make a connection between your
UITabBarController
and your application delegate?如果您的 ViewController 是
UITabBarController
,您需要将 self 设置为它的委托,因为您无法直接更改UITabBar
的委托。例如,在
UITabBarController
的 ViewDidLoad 中:If your ViewController is a
UITabBarController
, you need to set self as it's delegate because you can't change the delegate of theUITabBar
directly.For example, in the ViewDidLoad of your
UITabBarController
:我添加了以下
tabBarController.delegate = self;
,一切都很好。我希望这对其他人有帮助。I added the following
tabBarController.delegate = self;
and all is well. I hope this is helpful to others.