Set UITabBarController created in Interface Builder as delegate

后端 未结 4 1915
北荒
北荒 2021-01-05 08:33

I created my iOS app with Tab Bar template, so here is UITabBarController with bar buttons. An issue is how to set it as delegate. I found at SO that it has to be set progra

4条回答
  •  暖寄归人
    2021-01-05 08:57

    What about create a viewController lets say MyTabController subclass UITabBarController

    @interface MyTabController : UITabBarController
    

    and set the tab Controller's class in you storyboard to MyTabController instead of UITabBarController, then put self.delegate = self; in your viewDidLoad

    implement:

    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
    

    and here you are.

    Edit:

    If you find self.delegate = self; is odd, which it is, you can create an outlet in your MyTabController

    IBOutlet UITabBarController *tabBarController; and connect it to the tab controller in your storyboard.
    

    Then you can put tabBarController.delegate = self;

提交回复
热议问题