Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard - UITabBarController

Tags:

ios

ios5

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!

like image 774
Clarke76 Avatar asked Dec 01 '11 05:12

Clarke76


People also ask

What is UITabBarController?

A container view controller that manages a multiselection interface, where the selection determines which child view controller to display.

How do I add a TabBar controller to my storyboard?

Adding a Tab Bar Controller with View Controllers. The Interface Builder is an easy way to implement a Tab Bar Controller. Open Main. storyboard in the Interface Builder. Drag a Tab Bar Controller from the Object Library to the UI Preview pane.


1 Answers

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;
like image 185
abelsey Avatar answered Nov 15 '22 16:11

abelsey