Reputation: 638
i am trying to get a window to show (which it successfully does) on first launch, there is a button on that window (for testing purposes) that sets the bool firstLaunch = NO. for some reason, after pressing the button, the view is not dismissed.
app delegate
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:firstLaunch forKey:@"firstLaunch"];
newViewController = [[NewView alloc]init];
newViewController.appDelegateOutlet = self;
[userDefaults synchronize];
if ([userDefaults boolForKey:@"firstLaunch"]) {
NSLog(@"first launch");
[_window addSubview:newViewController.view];
[userDefaults synchronize];
}
if (![userDefaults boolForKey:@"firstLaunch"]) {
[userDefaults synchronize];
NSLog(@"not first launch");
button
-(IBAction)dismissFirstLaunch:(id)sender{
NSLog(@"%@",appDelegateOutlet);
appDelegateOutlet.firstLaunch = NO;
[appDelegateOutlet.userDefaults setBool:appDelegateOutlet.firstLaunch forKey:@"firstLaunch"];
[appDelegateOutlet.userDefaults synchronize];
NSLog(@"%@",[appDelegateOutlet.userDefaults objectForKey:@"firstLaunch"]);
}
fixed:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:firstLaunch forKey:@"firstLaunch"];
newViewController = [[NewView alloc]init];
newViewController.appDelegateOutlet = self;
[userDefaults synchronize];
if ([userDefaults boolForKey:@"firstLaunch"]) {
NSLog(@"YE BOY!!");
[_window addSubview:newViewController.view];
[userDefaults synchronize];
}
else
[self continueLaunch];
return YES;
}
Upvotes: 1
Views: 294
Reputation: 38475
Maybe I'm being blind but there's not a line of code in your button's action to tell it to dismiss the view? It's not psychic - how would it know to dismiss the view unless you tell it to!
PS You're also going to run into problems with your logic to determine if it's the first run - I bet the view is being shown every time :)
Upvotes: 2