msgambel
msgambel

Reputation: 7340

Set a UITabBarController delegate in a UIStoryboard

I've been searching for this, can't find the answer.

I'm setting up a UIStoryboard in Interface Builder, and while everything is working fine, I seem to be unable to hook up the delegate outlet of the UITabBarController to any of the UIViewController's in the UIStoryboard, regardless of their position in the UIStoryboard. I've set the UIViewController's to be a <UITabBarControllerDelegate> in the .h file, but Interface Builder won't allow me to select the UIViewController as the delegate for the UITabBarController.

Has anyone run into this issue?

Upvotes: 3

Views: 3809

Answers (2)

msgambel
msgambel

Reputation: 7340

It turns out that the reason you can't set the delegate in the UIStoryboard is because you have no guarantee that the UIViewController is loaded before the UITabBar is loaded. Therefore, programmatically setting the delegate (in a different UIViewController) is the ONLY way to accomplish this.

Upvotes: 11

MoFlo
MoFlo

Reputation: 559

You'll need to do it programmatically in the application:didFinishLaunchingWithOptions method of your application delegate:

_tabBarController = (UITabBarController *)_window.rootViewController; _tabBarController.delegate = self;

Upvotes: 5

Related Questions