0

我正在设置将出现在我的应用程序启动中的第一个视图控制器。它应该作为教程第一次出现 UIView,第二次出现另一个标准视图。在 AppDelegate 我写了这个:

#import "AppDelegate.h"
#import "TabBarController.h"
#import "TutorialController.h"

@implementation AppDelegate

@synthesize window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if ([@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"Startup"]]) {

        TabBarController * viewControllerStandard = [[TabBarController alloc] init];
        window.rootViewController = viewControllerStandard;

    } else {

        TutorialController * viewControllerFirst = [[TutorialController alloc] init];
        window.rootViewController = viewControllerFirst;
        }

    [window makeKeyAndVisible];

    return YES;
}

它不会返回任何警报,但是,启动应用程序,在启动画面之后,它只出现一个黑屏。没有这些代码,一切正常。有什么问题?谢谢!

编辑:我正在使用情节提要!

已解决:使用 followben 的回复解决。

4

2 回答 2

1

您需要初始化视图控制器。例如

#import "AppDelegate.h"
#import "TabBarController.h"
#import "TutorialController.h"

@implementation AppDelegate

@synthesize window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if ([@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"Startup"]]) {

        TabBarController *viewControllerStandard = [[TabBarController alloc] init];
        window.rootViewController = viewControllerStandard;
        [viewControllerStandard release]; //for non-arc

    } else { 

        TutorialController * viewControllerFirst = [[TutorialController alloc] init];
        window.rootViewController = viewControllerFirst; 
        [viewControllerFirst release]; //for non-arc

    }

    [window makeKeyAndVisible];

    return YES;
}
于 2013-10-20T21:19:22.247 回答
0

您没有实例化 viewControllerStandard。除非它是在 Interface Builder 中构建的,否则您将需要这样的东西。

self.viewControllerStandard = [[TabBarController alloc] init];
self.viewControllerFirst = [[TutorialController alloc] init];
[self.viewController setViewControllers:@[self.viewControllerFirst] animated:NO];
window.rootViewController = self.viewControllerStandard;
于 2013-10-20T21:20:09.000 回答