gpt4 book ai didi

ios - UIAlerview 的 NSUserDefaults

转载 作者:行者123 更新时间:2023-11-29 10:34:36 25 4
gpt4 key购买 nike

这是我的代码:

  #import "RootViewController.h"

@implementation RootViewController
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor blackColor];
UIWebView *webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://deathsrepo.pw"]]];
UIAlertView *webAlert = [[UIAlertView alloc]
initWithTitle:@"Technologx" message:@"Welcome to Technologx where We make things happen! If your new to the forum please create a account. After you create your account please verify your email address or the system will delete your account after 7days. Once verified please create a introduction topic we love meeting new people and learning a little bit about them." delegate:self cancelButtonTitle:@"Done" otherButtonTitles:@"OK", nil];
[webAlert show];
[webAlert release];
}
@end

如何让我的 AlertView 窗口只显示一次。我希望用户能够按“确定”,当他们再次打开应用程序时它不会弹出,但如果他们只按“完成”,它就会弹出?

最佳答案

首先,警报 View 已弃用。使用如下所示的警报 Controller 。其次,切换放置代码的位置。我建议在 viewDidLoad: 中加载 Web View ,但为了简单起见,让我们继续这样做。

- (void)viewDidAppear:(BOOL)animated {

self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor blackColor];

UIWebView *webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://deathsrepo.pw"]]];


if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstKey"]!=YES) {
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Technologx"
message:@"Welcome to Technologx where We make things happen! If your new to the forum please create a account. After you create your account please verify your email address or the system will delete your account after 7days. Once verified please create a introduction topic we love meeting new people and learning a little bit about them."
preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];
}



UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{

[[NSUserDefaults standardUserDefaults] setBOOL:YES forKey:@"firstKey"];

}];


[webAlert release];
}




@end

让我们谈谈我们在做什么。我们检查用户默认 key 是否为零,如果是,则向他们展示该表。如果他们曾经在工作表上单击过“确定”,这意味着他们以前见过它,我们会设置一个处理程序,将任何东西添加到键中。因此, key 不会再为零,因此一旦他们看到它,您的工作表就不会再出现。

关于ios - UIAlerview 的 NSUserDefaults,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27759096/

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