Reputation: 788
I can not figure out the following. My app, when is launching, it is hiding 5 images by default and they will be un-hidden later in code. Some of them. I was trying to set BOOL for NSUserDefaults when quitting the app to store informations, which pictures remained hidden, so next launch of the app suppose to check how many pictures were revealed from previous launch and set the .hidden method of these pictures to NO on launch. Means, if 3 of 5 were revealed, I need same 3 pictures to display next time.
Here's what I've got:
app.h
BOOL doneState;
app.m
- (void)viewDidLoad
{
[super viewDidLoad];
doneState = TRUE;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
done.hidden = [defaults boolForKey:@"hiddenDone"];
}
...
..
.
//---- When quitting app, save defaults (one example)
-(IBAction)flipBack:(id)sender{
doneState = TRUE;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:doneState forKey:@"hiddenDone"];
[defaults synchronize];
NSLog(@"Data Saved");
[self dismissModalViewControllerAnimated:NO];
}
NSLog prints "data saved" when quitting app, but when launching the app again, all pictures are hidden...
Can anybody please point me the right direction and what am I doing wrong here?
Thank you! A.
Upvotes: 0
Views: 214
Reputation: 788
Ok, I managed by myself. There is code below if anybody will need:
controller.h
BOOL doneState;
controller.m
//------ save data
if (img.hidden == NO) {
doneState = NO;
}
else {
doneState = YES;
}
[[NSUserDefaults standardUserDefaults] setBool:doneState forKey:@"hiddenDone"];
NSLog (@"Value of BOOL 1 = %@", doneState ? @"YES" : @"NO");
//display on load
BOOL saved = [[NSUserDefaults standardUserDefaults] boolForKey:@"hiddenDone"];
NSLog (@"Value of my saved BOOL = %@", saved ? @"YES" : @"NO");
img.hidden = saved;
Hope that helps! A.
Upvotes: 0