【发布时间】:2011-06-23 15:10:28
【问题描述】:
我试图在第一次启动时显示一个窗口(它成功地显示),该窗口上有一个按钮(用于测试目的)设置 bool firstLaunch = NO。出于某种原因,按下按钮后,视图没有被关闭。
应用委托
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");
按钮
-(IBAction)dismissFirstLaunch:(id)sender{
NSLog(@"%@",appDelegateOutlet);
appDelegateOutlet.firstLaunch = NO;
[appDelegateOutlet.userDefaults setBool:appDelegateOutlet.firstLaunch forKey:@"firstLaunch"];
[appDelegateOutlet.userDefaults synchronize];
NSLog(@"%@",[appDelegateOutlet.userDefaults objectForKey:@"firstLaunch"]);
}
固定:
- (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;
}
【问题讨论】:
标签: iphone cocoa-touch cocoa nsuserdefaults