How can I continue my count from the correct spot once I load the saved
count?
I am very new at coding, and am practicing and am making a simple
tally/counter app. I am trying to save and load the number so users can
continue where they left off once they close the app.
The save and load buttons work really well actually...except once I load
the saved number, and I press the +1 or -1 buttons, it starts from 0 as if
it were a fresh load of the app without the saved data.
How can I make it so when the user loads the saved number, the +1 and -1
buttons can read that loaded number?
This is my +1 button:
-(IBAction)Up:(id)sender; {
Number = Number + 1;
Count.text = [NSString stringWithFormat:@"%i", Number];
}
These are my save and load buttons:
-(IBAction)save {
NSString *savestring = Count.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:@"savestring"];
[defaults synchronize];
}
-(IBAction)load {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadstring = [defaults objectForKey:@"savestring"];
[Count setText:loadstring];
}
I feel like this is a simple fix.. and should be somewhere in the +1 Up
button... help?!
No comments:
Post a Comment