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

2 回答 2

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"];
于 2013-01-07T15:05:20.917 回答
0

您正在解散applicationDidFinishLaunching. 但是 AppDelegate 不是视图控制器,所以没有什么可以忽略的。

启动应用程序时您究竟想消除什么?我想你只是想展示正确的 VC,而不是解雇它。

此外,连续制作两个动画通常也不起作用。考虑animated:NO改为使用第一个。

于 2013-01-07T15:08:06.493 回答