UIAlertView,一旦用户打开应用程序。显示一次 [英] UIAlertView, once the user opens the app. Shown once

查看:127
本文介绍了UIAlertView,一旦用户打开应用程序。显示一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在用户打开应用程序后显示 UIAlertView 。它会要求他们的电子邮件地址。但我想它只显示一次。所以当用户重新打开应用程序时,uialertview不应弹出。并且 UIAlertView 将包含2个按钮。 'Dismiss'& 是..关闭按钮将继续与应用程序。

I want a UIAlertView to show, once the user opens the app. It'll ask them for their email address. But i want it to only show once. So when the user re opens the app the uialertview shouldnt pop up. And the UIAlertView will contain 2 buttons within that. 'Dismiss' & 'Yes' .. the dismiss button will continue with the app. But the 'Yes' will take them to another view'.

感谢:)
编辑:

Thanks :)

- (void)viewDidLoad {
    [super viewDidLoad];

if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"alert"]]) {
    [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"alert"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Enter your email" 
                                                     message:@"\n\n\n" 
                                                    delegate:nil 
                                           cancelButtonTitle:@"Cancel" 
                                           otherButtonTitles:@"Enter", nil];

    textField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)]; 
    [textField setBackgroundColor:[UIColor whiteColor]];
    [textField setPlaceholder:@"enter email here"];
    [prompt addSubview:textField];



    [prompt show];
    [prompt release];


    //[textField becomeFirstResponder];

}
}

推荐答案

您可以使用

http://developer.apple。 com / library / mac /#documentation / Cocoa / Reference / Foundation / Classes / NSUserDefaults_Class / Reference / Reference.html

// save 
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:true] forKey:@"hasRunBefore"];

// load 
[[NSUserDefaults standardUserDefaults] objectForKey:@"hasRunBefore"] boolValue];

这篇关于UIAlertView,一旦用户打开应用程序。显示一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆