2010-10-04 59 views
1

我想加載一個UIView,第一次加載我的應用程序。 但我無法做到這一點。在applicationdidFinishLaunching中加載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; 
} 

有人能幫助我嗎?

+0

您是否遇到任何錯誤,或者您的測試「AlreadyRan」總是失敗,因此您的代碼沒有執行? – 2010-10-04 20:32:20

回答

1

一種可能性是你永遠不會同步NSUserDefaults。您需要添加一個[[NSUserDefaults standardUserDefaults] synchronize]調用,或者在applicationWillTerminate和/或applicationDidEnterBackground中。