您好,我正在尝试在 UIAlertView
中查看两个文本字段,但显示错误。我使用下面的代码来查看文本字段。
- (void)viewDidLoad
{
[super viewDidLoad];
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!"
message:@"Please 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) 超出文本字段数组的范围”
请告诉我上面代码中哪里做错了,并请告诉我如何解决此问题。
最佳答案
参见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 *)textFieldAtIndex:(NSInteger)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/