我的 UITabBarController 的 didSelectViewController 方法没有被调用?

发布于 2024-08-27 07:50:36 字数 592 浏览 4 评论 0原文

这是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

子栖 2024-09-03 07:50:36

您是否在 UITabBarController 和应用程序委托之间建立了连接?

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
     ...
     tabBarController.delegate = self;
     ...
}

Did you make a connection between your UITabBarController and your application delegate?

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
     ...
     tabBarController.delegate = self;
     ...
}
归属感 2024-09-03 07:50:36

如果您的 ViewController 是 UITabBarController,您需要将 self 设置为它的委托,因为您无法直接更改 UITabBar 的委托。

例如,在 UITabBarController 的 ViewDidLoad 中:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.delegate = self;
}

If your ViewController is a UITabBarController, you need to set self as it's delegate because you can't change the delegate of the UITabBar directly.

For example, in the ViewDidLoad of your UITabBarController :

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.delegate = self;
}
无妨# 2024-09-03 07:50:36

我添加了以下 tabBarController.delegate = self; ,一切都很好。我希望这对其他人有帮助。

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    // Add the tab bar controller's current view as a subview of the window
    tabBarController.delegate = self;
    [window addSubview:tabBarController.view];
}

I added the following tabBarController.delegate = self; and all is well. I hope this is helpful to others.

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    // Add the tab bar controller's current view as a subview of the window
    tabBarController.delegate = self;
    [window addSubview:tabBarController.view];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文