going crazy here. can anyone tell me what's wrong with this code? the userdefault has set the Bool to NO, but during the runloop's checkRotate method, the console prints "Rotated", signifying that the bool is yes...
if there is nothing wrong with this code, please comment so at least i'll know for sure, and if there is something wrong with it, i'd love to know what it is!
if there is nothing wrong with this code, please comment so at least i'll know for sure, and if there is something wrong with it, i'd love to know what it is!
Code:
//.h
BOOL didRotate;
//.m
+ (void)initialize
{
NSMutableDictionary *userDefaultsDictionary = [NSMutableDictionary dictionary];
[userDefaultsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"Rotated"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults:userDefaultsDictionary];
[defaults synchronize];
}
- (void)viewWillAppear:(BOOL)animated
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:@"Rotated"] == YES)
didRotate = YES;
else
didRotate = !didRotate;
[self checkRotate];
[super viewWillAppear:animated];
}
- (void)checkRotate
{
if (didRotate)
{
NSLog(@"Rotated");
}
else
{
NSLog(@"Not Rotated");
}
}
- (void)viewWillDisappear:(BOOL)animated
{
didRotate = !didRotate;
[super viewWillDisappear:animated];
}