Clarke76
Clarke76

Reputation: 774

Storyboard - UITabBarController

I was playing around with iOS 5 and storyboards today. I currently have it so that the main storyboards starts with a uitabbarcontroller then a navigationviewcontroler and finally a uiviewcontroller. All that works fine.

What I'm looking for is how to dynamically set which viewconotroller the uitabbarcontroller is displaying when the application starts. So I'd want to use CoreData to see if a table was empty and it it was select the second viewcontroller (tabbar item 2) and if not select the first viewcontroller (tabbar item 1).

Since the storyboard is handling what is being displayed, I wasn't sure how in the app delegate I could set this?

Hoping someone can point me in the right direction here!

Thanks!

Upvotes: 19

Views: 8934

Answers (2)

Leander
Leander

Reputation: 752

For me I can access the tabbar using self.navigationController.parentViewController; This always return the tabbar controller.

Upvotes: 0

abelsey
abelsey

Reputation: 286

Your app delegate will have a window property. That can be used to get a pointer to the storyboard's initial view controller (which will be your UITabBarController), like this example from one of my app delegates application:didFinishLaunchingWithOptions:

UITabBarController *tabController =
   (UITabBarController *)self.window.rootViewController;
tabController.selectedIndex =
   [defaults integerForKey:kOptionLastTabSelectedKey];
tabController.delegate = self;

Upvotes: 27

Related Questions