Hello all,
I have looked at other answers and the docs. Maybe I am missing something, or maybe I have another issue. I am trying to save a number on exiting the app, and then when the app is loaded I want to check if this value exists and take action accordingly. This is what I have tried:
To save on exiting:
- (void)applicationWillTerminate: (UIApplication *) application
{
double save = [label.text doubleValue]; // This could be the issue
//double save = 3.5; // This works, it saves the value and loads it fine, so that is not the problem here.
[[NSUserDefaults standardUserDefaults] setDouble: save forKey: @"savedNumber"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
To check:
- (IBAction)buttonclickSkip{
double save = [[NSUserDefaults standardUserDefaults] doubleForKey: @"savedNumber"];
if (save == 0) {
[self performSelector:@selector(displayAlert) withObject:nil];
test.enabled = YES;
test.alpha = 1.0;
skip.enabled = NO;
skip.alpha = 0.0;
}
else {
label.text = [NSString stringWithFormat:@"%.1f %%", save];
}
}
The problem is I always get my alert message displayed, the saved value is not put into the label so somehow == 0 is always true. Why would:
double save = [label.text doubleValue];
always equal zero? Before I close the app the number in that label is roughly 0.5% (it varies). If it makes any difference I am testing this on the iPhone simulator.
Many thanks,
Stu