Search code examples
iosswiftuiviewcontrolleruitabbarcontrolleruitabbar

Access UITabBarController to assign action via Storyboards


Without storyboards, I can simply assign the UITabBarController.delegate = self (in AppDelegate, for example). This lets me handle what happens when a UITabBarButton on the UITabBar is pressed.

However, I'm now using storyboards, where my UIViewController is contained in a UINavigationController, which is contained in a UITabBarController.

What's the best way to access this parent UITabBarController in code? I'd like to do this so I can assign a delegate to it. When the user presses a button in the UITabBar, I want to take an action in my contained UIViewController.


Solution

  • self.navigationController?.tabBarController