简体   繁体   English

故事板 - UITabBarController

[英]Storyboard - UITabBarController

I was playing around with iOS 5 and storyboards today. 今天我正在玩iOS 5和故事板。 I currently have it so that the main storyboards starts with a uitabbarcontroller then a navigationviewcontroler and finally a uiviewcontroller. 我目前拥有它,以便主要故事板以uitabbarcontroller开始,然后是navigationviewcontroler,最后是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. 我正在寻找的是如何动态设置应用程序启动时uitabbarcontroller正在显示哪个viewconotroller。 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). 所以我想使用CoreData来查看表是否为空它是否选择了第二个viewcontroller(tabbar项目2),如果没有则选择第一个viewcontroller(tabbar项目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! 谢谢!

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)的指针,就像我的一个app delegates应用程序中的这个例子:didFinishLaunchingWithOptions:

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

For me I can access the tabbar using self.navigationController.parentViewController; 对我来说,我可以使用self.navigationController.parentViewController访问tabbar; This always return the tabbar controller. 这总是返回标签栏控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM