2013-01-07 55 views
0

我得到這個錯誤「應用程序試圖在目標上呈現一個零模式視圖控制器。」 這是我有的代碼,我試圖設置,如果條件滿足,它會改變初始視圖控制器。爲什麼我會呈現無模式視圖控制器?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"logged_in"]) { 


    ViewControllerOne *vc1 = [[ViewControllerOne alloc]init]; 
    vc1=[self.storyboard instantiateViewControllerWithIdentifier: @"vc1"]; 




    [self presentViewController:vc1 animated:YES completion:Nil]; 





} else { 

    ViewControllerTwo *vc2 = [[ViewControllerTwo alloc]init]; 
    vc2=[self.storyboard instantiateViewControllerWithIdentifier: @"vc2"]; 




    [self presentViewController:vc2 animated:YES completion:Nil]; 

} 
// Override point for customization after application launch. 
return YES; 
} 
+0

清理你的項目一次並重建它,希望它解決你的問題 –

回答

0

我用的是什麼,我認爲你缺少的UIWindow

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil]; 
    UIViewController *mainViewController = [storyboard instantiateInitialViewController]; 
    self.window.rootViewController = mainViewController; 

    return YES; 
} 

然後你就可以更換:

[storyboard instantiateInitialViewController]; 

有:

[self.storyboard instantiateViewControllerWithIdentifier: @"vc1"]; 
+0

我相信如此,我設置了故事板ID上的vc1和vc2。 – moo

+0

我相信self.stroyboard我沒有做,我該如何設置 – moo

+0

我在哪裏添加此代碼?我相信我知道在哪裏添加代碼,但只是爲了確保。 – moo

0

你是解僱一個視圖控制器applicationDidFinishLaunching。但是AppDelegate不是視圖控制器,所以沒有什麼可以解僱的。

在啓動應用程序時,您想要關閉什麼?我想你只想目前正確的VC,而不是解僱它。

另外,連續做兩個動畫也不起作用。請考慮使用animated:NO代替。

+0

對不起,編輯了代碼,我不小心添加了解僱只是爲了看看會發生什麼,相同的結果。 – moo

相關問題