Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从警报中的文本字段获取输入文本_Ios_Objective C_Uialertcontroller - Fatal编程技术网

Ios 如何从警报中的文本字段获取输入文本

Ios 如何从警报中的文本字段获取输入文本,ios,objective-c,uialertcontroller,Ios,Objective C,Uialertcontroller,此问题以前曾在中提出过。但是,是否有人拥有Objective-C语言的代码 提前谢谢 到目前为止,我得到的是: UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Adding A Row" message:@"Enter A Number" preferredStyle:UIAlertControllerStyleAlert]; [alert addTextFieldWithConf

此问题以前曾在中提出过。但是,是否有人拥有Objective-C语言的代码

提前谢谢

到目前为止,我得到的是:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Adding A Row"
    message:@"Enter A Number"
    preferredStyle:UIAlertControllerStyleAlert];

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

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    [alert dismissViewControllerAnimated:YES completion:nil];
}];

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//Do some action here
}];

[alert addAction:cancel];
[alert addAction:ok];

[self presentViewController:alert animated:YES completion:nil];

您需要使用与
Swift
中相同的逻辑:在操作处理程序中以以下方式写入
alert.textFields[0]。text

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    NSString *input = alert.textFields[0].text;
    NSLog(@"input was '%@'", input);
}];
在我的测试照片里

输入为“1234”


这应该不难翻译。到目前为止,您拥有Objective-C代码的哪一部分?您是否已经创建了
UIAlertController
?你添加了文本字段吗?我已经添加了文本字段。与……有麻烦。从文本字段中获取值,并在用户单击“确定”时打印它。alert.addAction(UIAlertAction(标题:“确定”,样式:。默认,处理程序:{(操作)->Void in let textField=alert.textFields![0]作为UITextField println(“文本字段:(textField.Text)”)})好的,请显示您已经获得的代码以及您认为需要帮助的地方,如果你展示你当前的代码,我很乐意提供一些。它成功了!谢谢D