在IOS 7中的UIAlertview iOS上的多个文本字段
所以新的iOS 7已经出来,我试图添加多个textFields和标签到UIAlertviews。 我需要三个。 我一直试图添加他们作为子视图,并不再工作。 我也尝试添加UIAlertViewStylePlainTextInput多行,但它似乎只返回一个文本字段。
我需要添加标签以向他们显示要input的内容。 有没有办法用新的iOS 7完成这个任务?
我发现在iOS7中使用UIAlertView与多个文本字段唯一的解决scheme是仅用于login。
使用这一行来初始化你的alertView
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
而这个来抓取用户的input:
user = [alert textFieldAtIndex:0].text; pw = [alert textFieldAtIndex:1].text
除了login之外的其他目的, 在iOS7中查看UIAlertView的addSubview
您可以在iOS7的标准警报视图中将accessoryView更改为任何自定义的 customContentView
[alertView setValue:customContentView forKey:@"accessoryView"];
请注意,您必须在[alertView show]之前调用它。
最简单的说明示例:
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil]; UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]; v.backgroundColor = [UIColor yellowColor]; [av setValue:v forKey:@"accessoryView"]; [av show];
如果您只想向UIAlertView
添加两个文本字段,则可以使用UIAlertViewStyleLoginAndPasswordInput
并按以下方式修改文本字段:
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Some Title" message:@"Some Message." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"No, thanks", nil]; alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; [alert textFieldAtIndex:1].secureTextEntry = NO; //Will disable secure text entry for second textfield. [alert textFieldAtIndex:0].placeholder = @"First Placeholder"; //Will replace "Username" [alert textFieldAtIndex:1].placeholder = @"Second Placeholder"; //Will replace "Password" [alert show];
之后,在UIAlertView委托中,您可以简单地使用以下方法获取文本:
text1 = [alert textFieldAtIndex:0].text; text2 = [alert textFieldAtIndex:1].text;
- 为什么我不应该使用getter来释放objective-c中的属性?
- 是否可以生成通配符AppID的企业/内部供应configuration文件?
- iOS:在某些设备上多次调用MPMusicPlayerControllerPlaybackStateDidChangeNotification
- 使用自定义文件包UTI导出UIDocument
- 一个拥有多个品牌的iOS应用程序
- Cordova:从plugin.xml修改* -Info.plist
- 我如何限制我的iOS项目到iPhone 4只
- 如何在Swift 3.0中通过Segue传递variables和对象
- iOS应用程序在发行版中崩溃,但不在开发中,而Swift符号未解决