3

当我在 iPhone 6.0 模拟器中运行我的应用程序时,它显示

应用程序窗口应该在应用程序启动结束时有一个根视图控制器

在其他模拟器中它不存在。为什么?这个错误是什么意思?

我的应用程序的导航流程是这样的:首先我的应用程序应该显示登录屏幕。进入应用程序后,我需要显示一个带有标签栏的视图。在那个视图中会有很多按钮,当我们单击这些按钮时,它应该显示没有标签栏的相应视图控制器。这就是我将那些导航控制器添加到窗口的原因。

这是我的 didFinishLaunchingWithOptions 代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.tabBarController = [[UITabBarController alloc] init];
    self.window.rootViewController = self.tabBarController;

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor=[UIColor blackColor];

    [application setStatusBarStyle:UIStatusBarStyleBlackOpaque];

    Object1 = [[Class1 alloc] initWithNibName:@"Class1" bundle:nil];
    tempNav=[[UINavigationController alloc]initWithRootViewController:Object1];
    tempNav.navigationBar.hidden=YES;
    tempNav.view.frame  = CGRectMake(0.0f, 20.0f, 320.0f, 460.0f);
    self.window addSubview:tempNav.view]; 

    LoginObj = [[Login alloc] initWithNibName:@"Login" bundle:nil];
    navController=[[UINavigationController alloc]initWithRootViewController:LoginObj];
    navController.navigationBar.hidden=YES;
    navController.view.frame  = CGRectMake(0.0f, 20.0f, 320.0f, 460.0f);
    [self.window addSubview:navController.view];

    Obj2 = [[Class2 alloc] initWithNibName:@"Class2" bundle:nil];
    navController1=[[UINavigationController alloc]initWithRootViewController:Obj2];
    navController1.navigationBar.hidden=YES;
    navController1.view.frame  = CGRectMake(0.0f, 20.0f, 320.0f, 460.0f);
    [self.window addSubview:navController1.view];

    Obj3 = [[Class3 alloc] initWithNibName:@"Class3" bundle:nil];
    navController2=[[UINavigationController alloc]initWithRootViewController:Obj3];
    navController2.navigationBar.hidden=YES;
    navController2.view.frame  = CGRectMake(0.0f, 20.0f, 320.0f, 460.0f);
    [self.window addSubview:navController2.view];

    Obj4 = [[Class4 alloc] initWithNibName:@"Class4" bundle:nil];
    navController3=[[UINavigationController alloc]initWithRootViewController:Obj4];
    navController3.navigationBar.hidden=YES;
    navController3.view.frame  = CGRectMake(0.0f, 20.0f, 320.0f, 460.0f);
    [self.window addSubview:navController3.view];

    [self.window makeKeyAndVisible];

    return YES;  
}
4

2 回答 2

1

正如 wattson12 所说,您需要在您的应用程序委托中执行以下操作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
    self.window.rootViewController = self.mainViewController;    // you need this line!
    [self.window makeKeyAndVisible];
    return YES;
}

如果您没有明确设置UIWindow rootViewController 属性,您将看到此消息。

如果您使用 Xcode 4.5 创建一个新项目,它应该在模板应用程序委托中包含此代码。如果您使用的是在早期版本的 Xcode 中创建的项目,则该行可能会丢失,并且您会收到警告消息。

于 2012-10-04T09:40:39.563 回答
0

这意味着你没有设置你的 app rootViewController。首先从您的代码中删除这些行 -

[self.window addSubview:tempNav.view];  
[self.window addSubview:navController.view];  
[self.window addSubview:navController1.view];  
[self.window addSubview:navController2.view];  
[self.window addSubview:navController3.view];  

在你的代码中你正在使用UITabBarController但没有初始化它viewController的数组,所以这样做 -

self.tabBarController.viewControllers = [NSArray arrayWithObjects:tempNav, navController, navController1, navController2, navController3, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
于 2012-10-04T09:38:08.927 回答