您好,我正在尝试查看 UIAlertView 中的两个文本字段,但显示错误。我已经使用下面的代码来查看文本字段。
- (void)viewDidLoad
{
[super viewDidLoad];
UIAlertView * alert = [[UIAlertView alloc] initWithTitle"Hello!"
message"lease enter your details:"
delegate:self
cancelButtonTitle"Continue"
otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * name = [alert textFieldAtIndex:0];
name.keyboardType = UIKeyboardTypeAlphabet;
name.placeholder = @"Enter your name";
UITextField * phone = [alert textFieldAtIndex:1];
phone.keyboardType = UIKeyboardTypeNumberPad;
phone.placeholder = @"Enter your phone";
[alert show];
[alert release];
}
我已经使用上面的代码查看了两个文本文件,但我越来越喜欢了。 'textFieldIndex (1) 超出了文本字段数组的范围'
请告诉我我在上面的代码中哪里做错了,请告诉我解决这个问题。
Best Answer-推荐答案 strong>
查看 UIAlertView.h 文件
/* Retrieve a text field at an index - raises NSRangeException when
textFieldIndex is out-of-bounds. The field at index 0 will be the
first text field (the single field or the login field), the field at
index 1 will be the password field. */
- (UITextField *)textFieldAtIndexNSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);
这样做:
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
UITextField * name = [alert textFieldAtIndex:0];
name.keyboardType = UIKeyboardTypeAlphabet;
name.placeholder = @"Enter your name";
UITextField * phone = [alert textFieldAtIndex:1];
phone.secureTextEntry = NO;
phone.keyboardType = UIKeyboardTypeNumberPad;
phone.placeholder = @"Enter your phone";
关于ios - 在 UIAlertView 试图查看两个文本字段。它显示文本字段数组iOS7的错误范围,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/23193317/
|