【发布时间】:2016-01-06 19:42:39
【问题描述】:
这个问题之前有人问过,在:Get input value from TextField in iOS alert in Swift。但是,有人有 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];
【问题讨论】:
-
这应该不难翻译。到目前为止,您拥有 Objective-C 代码的哪一部分?您是否已经创建了
UIAlertController?您添加了文本字段吗? -
我已经添加了一个文本字段。遇到问题://3。从文本字段中获取值,并在用户单击确定时打印它。 alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in let textField = alert.textFields![0] as UITextField println("Text field: (textField.text) ") }))
-
好的,请出示您已经获得的代码以及您认为需要帮助的地方,如果您出示您当前的代码,我们很乐意提供一些。
标签: ios objective-c uialertcontroller