我想在NSUserDefault中保存和檢索值。我正在成功保存並檢索價值。但是,當我去cak主頁,並再次進入我的課程價值不存儲和所有的過程再次完成。它不記得舊的價值。如何將整數值保存到NSuserDefault,如sqlite?
我做這個 -
-(void)ViewDidLoad{
A = 0; // int A; defone in .h
[self calling_Once];
}
-(void)calling_Once{
NSLog(@"A is: %d",A); // A is always zero when I leave this class and return Back to this class. This is my only problem. I want A=1; when I go back And return to this class but
NSInteger B = [[NSUserDefaults standardUserDefaults] integerForKey:@"save_Interger_Value_For_Formula_One"]; //is not able to remeber value. It gives A=0; B =0; When I come back to this class, I want It should return A=1; B=1; and remember old value like sqlite when I return to this class.
if (A==0) {
[self refreshButton];
NSLog(@"Before Increment A is: %d",A);
A++;
NSLog(@"After Increment A is: %d",A);
[[NSUserDefaults standardUserDefaults] setInteger:A forKey:@"save_Interger_Value_For_Formula_One"];
}
NSInteger B = [[NSUserDefaults standardUserDefaults] integerForKey:@"save_Interger_Value_For_Formula_One"];
B = A;
NSLog(@" B is: %d",B);
B = A;
NSLog(@" A is: %d",A);
}
任何想法或建議將是非常歡迎的。
'[[NSUserDefaults standardUserDefaults] synchronize];',重複數百次。 – 2013-07-15 06:13:32
-synchronize在單個進程中根本無法幫到您 –
那麼,我該怎麼辦?你能給我一些想法嗎? –