gpt4 book ai didi

iphone - NSUserDefaults 仅在首次启动时显示窗口

转载 作者:行者123 更新时间:2023-12-03 17:06:34 25 4
gpt4 key购买 nike

我试图在第一次启动时显示一个窗口(它成功地做到了),该窗口上有一个按钮(用于测试目的),用于设置 bool firstLaunch = NO。由于某种原因,按下按钮后, View 不会消失。

应用程序委托(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");

按钮

-(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;
}

最佳答案

也许我是盲目的,但你的按钮操作中没有一行代码来告诉它关闭 View ?它不是通灵的——除非你告诉它,它怎么知道要消除 View !

PS 您还会遇到逻辑问题来确定这是否是第一次运行 - 我敢打赌每次都会显示 View :)

关于iphone - NSUserDefaults 仅在首次启动时显示窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6456329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com