如何在警报视图IOS中创建两个文本字段

我想创建一个包含两个uitextfields的alertview.
method:
//show alertview for file input
- (IBAction)showAddFiles:(id)sender {
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter File Details"
                                                      message:nil
                                                     delegate:self
                                            cancelButtonTitle:@"Cancel"
                                            otherButtonTitles:@"Add",nil];



    UITextField *textFieldDescription = [message textFieldAtIndex:0];
    textFieldDescription.placeholder = @"File Description : Ex. Acat Briefing";
    UITextField *textFieldFileName = [message textFieldAtIndex:1];
    textFieldFileName.placeholder = @"Exact File Name : Ex. acat.pdf";


    [message show];
}


//make sure file description is long enoguh
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    Nsstring *inputText = [[alertView textFieldAtIndex:0] text];

    if( [inputText length] <= 15 && [inputText length] >= 4)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

//handle add button
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    Nsstring *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Add"])
    {
        UITextField *fileDescription = [alertView textFieldAtIndex:0];
        UITextField *fileName = [alertView textFieldAtIndex:1];
        NSLog(@"Desc: %@\nName: %@",fileDescription.text,fileName.text);
    }
}

错误

*由于未捕获的异常’NSinvalidargumentexception’终止应用程序,原因:’textFieldindex(0)超出了文本字段数组的范围’

为什么我会收到此错误,如何在警报视图中创建两个uitextfield?

=========工作解决方案===========
感谢下面的答案,当你只需要两个纯文本字段时

//show alertview for file input
- (IBAction)showAddFiles:(id)sender {
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter File Details"
                                                      message:nil
                                                     delegate:self
                                            cancelButtonTitle:@"Cancel"
                                            otherButtonTitles:@"Add",nil];



    [message setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
    UITextField *fileDescription = [message textFieldAtIndex:0];
    fileDescription.placeholder=@"Ex. acat.pdf";
    [[message textFieldAtIndex:1] setSecureTextEntry:NO];
    UITextField *fileName= [message textFieldAtIndex:1];
    fileName.placeholder=@"Ex. Acat Briefing";

    [message show];
}

解决方法

分配“消息”警报视图后.将其添加到您的代码中:
[message setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
[[message textFieldAtIndex:1] setSecureTextEntry:NO];

这将使您的警报视图内部有两个文本字段.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...