在applicationdidFinishLaunching中加载UIView

时间:2010-10-04 20:26:26

标签: iphone cocoa-touch

我想加载UIView,第一次加载我的应用。 但我无法实现它。

这是我的applicationdidFinishLaunching方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"AlreadyRan"] ) {
        [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"AlreadyRan"];
        // proceed to do what you wish to only on the first launch
        NarrativeView *narView = [[NarrativeView alloc] initWithNibName:@"NarrativeView" bundle:nil];
        [window addSubview:narView.view];
        [window makeKeyAndVisible];
        [narView release];      
    } else 
    {
        // Override point for customization after application launch.
        [window addSubview:rootController.view];
        [window makeKeyAndVisible];
    }
    return YES;
}

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

可能是您永远不会同步NSUserDefaults。您需要在此处或在applicationWillTerminate和/或applicationDidEnterBackground中添加[[NSUserDefaults standardUserDefaults] synchronize]调用。