我想创建一个包含两个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]; }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。