2011-04-18 17 views

回答

1

在您的應用程序委託粘貼此:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 
    [defaults setBool:YES forKey:@"myKey"]; 
} 
- (void)applicationDidBecomeActive:(UIApplication *)application { 
    BOOL myKey = [defaults boolForKey:@"myKey"]; 
} 
2

NSUserDefaults的使用寫入到文件上的文件目錄。將BOOL存儲在NSNumber容器中([NSNumber numberWithBool:boolValue])。要在啓動時檢索該值,請從NSNumber容器對象([someNumberObject boolValue])中獲取該值。很基本的東西說實話。

編輯:檢查這個職位爲例:how can i read from the documents directory in the iphone at run time?

+0

'NSUserDefaults'有方法可以直接存儲和檢索的bool - '-setBool:ForKey :'和'-boolForKey:' – JeremyP 2011-04-18 10:25:15

+0

你能告訴我一個例子嗎? – CrazyDev 2011-04-18 10:28:50