My UITabBarController's didSelectViewController method is not getting called?

后端 未结 3 1469
野的像风
野的像风 2021-01-14 07:01

Here is my code stub for my app-delegate.m -- it never gets called.

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(         


        
相关标签:
3条回答
  • 2021-01-14 07:27

    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;
    }
    
    0 讨论(0)
  • 2021-01-14 07:28

    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];
    }
    
    0 讨论(0)
  • 2021-01-14 07:30

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

    - (void)applicationDidFinishLaunching:(UIApplication *)application
    {
         ...
         tabBarController.delegate = self;
         ...
    }
    
    0 讨论(0)
提交回复
热议问题