2012-10-04 26 views
3

當我在iPhone 6.0模擬器中運行我的應用程序,它顯示預計將有一個根視圖iPhone 6.0模擬器:應用程序窗口預計將有在應用程序啓動的最後一個根視圖控制器

應用程序窗口控制器在應用程序啓動結束時

在其他模擬器中它不存在。爲什麼? 這個錯誤是什麼意思?

我的應用程序的導航流程如下:首先,我的應用程序應顯示登錄屏幕。進入應用程序後,我需要用tabbar顯示一個視圖。在這個視圖中有很多按鈕會在那裏,當我們點擊這些按鈕時,它應該顯示沒有tabbar的相應視圖控制器。這就是爲什麼我將這些導航控制器添加到窗口。

這裏是我的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; 
} 
+0

你可以包含你的應用程序:didFinishLaunchingWithOptions代碼。這可能是發生這種情況的地方。 – Fogmeister

+1

這表明對我所有的仿真,它發生在你把你的RootViewController的的視圖窗口,而不是設置RootViewController的屬性 – wattson12

回答

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; 
} 

如果您沒有明確設置UIWindowrootViewController property,您會看到此消息。

如果您使用Xcode 4.5創建新項目,它應該在模板應用程序委託中包含此代碼。如果您使用的是在早期版本的Xcode中創建的項目,那麼該行可能會丟失,並且您會收到警告消息。

0

這意味着你沒有設置你的應用程序代碼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]; 
+0

我需要做的是這樣的:首先我的應用程序應該顯示登錄界面。進入應用程序後,我需要用tabbar顯示一個視圖。在這個視圖中有很多按鈕會在那裏,當我們點擊這些按鈕時,它應該顯示沒有tabbar的相應視圖控制器。這就是爲什麼我將這些導航控制器添加到窗口。 – Dev

+0

是的,不要在窗口上多次添加導航控制器。如果你想設置與tabbarcontroller導航控制器,然後做這樣......,你在你的問題中提到這 – TheTiger

+0

?你應該把它寫在你的問題....用於登錄屏幕上,爲的firstView您的應用程序的RootViewController的,然後在secondView控制器的viewDidLoad:方法,你可以添加此的TabBar像[self.view addSubView:tabBarController.View]。 – TheTiger

相關問題