在iPhone中显示带有文本框的alertview [英] Showing a alertview with a textbox in iPhone

查看:106
本文介绍了在iPhone中显示带有文本框的alertview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在AppStore应用程序中显示带有文本框的alertview。
它在这样的对话框中要求密码。
我看过至少一些其他第三方应用程序使用它。它是私人API吗?

Is it possible to show an alertview with a textbox inside like the AppStore app. It asks for password in such a dialog. I've seen atleast a couple of other third party apps using it. Is it a private API?

推荐答案

是的,它没有文件。要向UIAlertView添加文本字段,请使用addTextFieldWithValue:label:method。您调用默认文本作为第一个参数,并在空字段中显示的文本作为第二个。完成后,您可以通过使用textFieldAtIndex:n访问该字段。

Yes, it's undocumented. To add a text field to UIAlertView, use addTextFieldWithValue: label: method. You call with the default text as the first argument and the text that displays in an empty field as the second. Having done that, you can access the field via using textFieldAtIndex:n - see below.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Who are you?"     
                       message:@"Give your full name" 
                       delegate:self  cancelButtonTitle:@"Cancel"   
                       otherButtonTitles:@"OK", nil]; 
[alert addTextFieldWithValue:@""label:@"Name"]; 

// Customise name field 
UITextField* name = [alert textFieldAtIndex:0]; 
name.clearButtonMode = UITextFieldViewModeWhileEditing; 
name.keyboardType = UIKeyboardTypeAlphabet; 
name.keyboardAppearance = UIKeyboardAppearanceAlert; 
[alert show]; 

下一个片段显示如何检索名称字段中的值:

The next snippet shows how to retrieve the value in the name field:

NSLog("Name is %@", [[modalView textFieldAtIndex:0] text]);

这篇关于在iPhone中显示带有文本框的alertview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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