Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在警报视图中提示用户输入文本_Iphone_Objective C_Ios_Cocoa Touch_Ios4 - Fatal编程技术网

Iphone 如何在警报视图中提示用户输入文本

Iphone 如何在警报视图中提示用户输入文本,iphone,objective-c,ios,cocoa-touch,ios4,Iphone,Objective C,Ios,Cocoa Touch,Ios4,我正在编写一段代码,如果我可以使用类似UIAlertView的弹出框,并提示用户输入密码之类的文本,那将是最好的。 有什么关于优雅方式的建议吗 我发现最好的方法是遵循本教程: 实现这一点所用的代码如下(直接取自那本很棒的教程): 如果我的应用程序在一两个月内还没有发布,那么我会登录,查看iOS 5测试版区域,看看UIAlertView是否为我们准备了一些东西。我想知道UIAlertView不是模态的,这样警报就不会被阻止,这会很有帮助 我遇到了这样一个问题,我想提示用户输入,然后继续,然后在以

我正在编写一段代码,如果我可以使用类似UIAlertView的弹出框,并提示用户输入密码之类的文本,那将是最好的。
有什么关于优雅方式的建议吗

我发现最好的方法是遵循本教程:

实现这一点所用的代码如下(直接取自那本很棒的教程):


如果我的应用程序在一两个月内还没有发布,那么我会登录,查看iOS 5测试版区域,看看
UIAlertView
是否为我们准备了一些东西。

我想知道UIAlertView不是模态的,这样警报就不会被阻止,这会很有帮助

我遇到了这样一个问题,我想提示用户输入,然后继续,然后在以后的代码中使用该输入。但是,[alert show]之后的代码将首先运行,直到您到达运行循环的末尾,然后将显示警报。

优化代码:

UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:@"Password"
                                                        message:@"Please enter the password:\n\n\n"
                                                       delegate:self
                                              cancelButtonTitle:NSLocalizedString(@"Cancel",nil)
                                              otherButtonTitles:NSLocalizedString(@"OK",nil), nil];

UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(16,83,252,25)];
passwordField.borderStyle = UITextBorderStyleRoundedRect;
passwordField.secureTextEntry = YES;
passwordField.keyboardAppearance = UIKeyboardAppearanceAlert;
passwordField.delegate = self;
[passwordField becomeFirstResponder];
[passwordAlert addSubview:passwordField];

[passwordAlert show];
[passwordAlert release];
[passwordField release];

在iOS 5中要简单得多,只需将alertViewStyle属性设置为适当的样式(UIAlertViewStyleSecureTextInput、UIAlertViewStylePlainTextInput或UIAlertViewStyleLoginAndPasswordInput)。例如:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Password" message:@"Enter your password:" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
[alertView show];

>很简单,你可以这样申请

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Filename" message:@"Enter the file name:" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
[alertView show]

删除图像、字体和背景颜色指定。添加passwordField.borderStyle=UITextBorderStyleRoundedRect;[passwordAlert setTransform:CGAffineTransformMakeTransform(0109)];是过时的。知道这可以做到真的很好,但xcoder的答案对于iOS5及以上版本要好得多。。。
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Filename" message:@"Enter the file name:" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
[alertView show]