目标:
当我的应用程序启动时 - 我需要它在显示视图才能进入“主页”屏幕。它是一个标签栏应用程序,此视图不是标签栏的一部分。
我正在使用Storyboards和Xcode 5 - 仅限iOS7应用。
问题:
我的代码会检查应用是否首次启动。基于此,我想向用户呈现一次性视图。
我尝试了什么:
以下代码位于应用程序的appDelegate中,因为这是它全部启动的地方。我在那里调用以下代码:
-(void)showCountrySettings
{
if (self.termsHaveBeenAccepted){
BBCounterySettingsViewController *countrySettings = [[BBCounterySettingsViewController alloc]initWithNibName:@"View" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"];
[self.navigationController pushViewController:vc animated:YES];
}
由于[self.navigationController..]
不存在,我收到编译错误。 [self.tabbarcontroller...];
这很明显,因为我没有为这些设置属性 - 但是如何解决此问题并将标签栏连接到故事板?
我错过了什么?
答案 0 :(得分:1)
以编程方式更改窗口的rootviewcontroller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *aStoryBoard=[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UITabBarController *aTabCtrl=[aStoryBoard instantiateViewControllerWithIdentifier:@"Tab"];
FirstVC *aFirstCtrl=[aStoryBoard instantiateViewControllerWithIdentifier:@"First"];
if(self.termsHaveBeenAccepted)
self.window.rootViewController=aFirstCtrl;
else
self.window.rootViewController=aTabCtrl;
return YES;
}
这肯定会对我测试过。
答案 1 :(得分:1)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
if(!isAgreementAccepted)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDD"];
self.window.rootViewController=vc;
}
return YES;
}
如果未接受协议,请在用户点击接受按钮后将T& C viewController
设置为rootViewController
,然后将TabBarviewController
设置为root。
你可以通过应用委托代理访问寡妇对象
[[[UIApplication sharedApplication]delegate] window].rootViewController=tabViewController.
答案 2 :(得分:0)
如果Tabbarcontroller是您的根视图控制器,那么使用下面的代码将解决您的appdelegate中的问题。
-(void)showCountrySettings
{
if (self.termsHaveBeenAccepted){
BBCounterySettingsViewController *countrySettings = [[BBCounterySettingsViewController alloc]initWithNibName:@"View" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"];
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
[tabBarController presentModalviewcontroller:vc animated:YES completionblock:nil];
}
答案 3 :(得分:0)
添加tabbarcontroller的viewcontroller superview作为第一次调用tabbarcontroller单独