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

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

概述我想创建一个包含两个uitextfields的alertview. method://show alertview for file input- (IBAction)showAddFiles:(id)sender { UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter File Details" 我想创建一个包含两个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];

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

总结

以上是内存溢出为你收集整理的如何在警报视图IOS中创建两个文本字段全部内容,希望文章能够帮你解决如何在警报视图IOS中创建两个文本字段所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1099166.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存