我试图显示从获得了一些文本textfield
的uialertview
,比我想说明文成UILabel
。
我觉得很难,有人可以帮助我吗?
- (IBAction)buttonPressed1:(id)sender {
//http://useyourloaf.com/blog/uialertcontroller-changes-in-ios-8/
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Hello Crazy" preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder = NSLocalizedString(@"Pet Name", @"Name");
}];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
[alert dismissViewControllerAnimated:YES completion:nil];
// self.labelText1.text = [NSString stringWithFormat:@"alert.textFields.firstObject"];
// self.labelText1.text = [NSMutableString stringWithString:@"alert.textFields.firstObject"];
self.labelText1.text = @" \?alert.textFields.firstObject\? ";
}];
[alert addAction:ok];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}
在这里你可以看到我想要显示的文字self.labelText1.text
,在这里这labeltext1接受一个字符串,但我想说明从获得的文本placeholder
的uialertview
。请给我一些建议...
您可以使用using获得文本字段alert.textFields
,它是的数组UITextField
。在您的情况下,该数组的第一个对象包含您要使用的文本字段:
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
UITextField *textField = alert.textFields.firstObject;
self.labelText1.text = textField.text;
// Do other stuffs
}];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句