Is my UITabBarController didSelectViewController method not called?

Here is my code for my delegate.m application - it is never called.

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"%s", __FUNCTION__);
}

Defined in this delegate.h application

@interface OrioleAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end
+3
source share
3 answers

Have you established a connection between your UITabBarControllerand the application delegate?

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

If your ViewController is UITabBarController, you need to configure self because it is delegated, because you cannot directly change the delegate from UITabBar.

For example, in your ViewDidLoad UITabBarController:

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

I added the following tabBarController.delegate = self;, and all is well. Hope this helps others.

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

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

Source: https://habr.com/ru/post/1738797/


All Articles