显示带文本字段输入的警报

Ass*_*ery 5 alert objective-c ios

如何在警报中显示文本输入字段以从用户获取输入并在应用程序中使用该输入(在标签上显示输入)?

如下图所示 在此输入图像描述 在此输入图像描述

感谢您的时间.

小智 15

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Text"
                                                                message:@"Enter some text below"
                                                         preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *submit = [UIAlertAction actionWithTitle:@"Submit" style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction * action) {

                                                   if (alert.textFields.count > 0) {

                                                       UITextField *textField = [alert.textFields firstObject];

                                                       textField.text // your text
                                                   }

                                               }];

[alert addAction:submit];

[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"something"; // if needs
}];

[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

7033 次

最近记录:

9 年,10 月 前