我在Swift中有一个UIAlertController(警报样式),一切工作正常。但我添加到它的UITextField是一个可选字段,用户不需要输入文本。问题是当我显示这个UIAlertController时,键盘会同时出现并默认选中文本框。除非用户点击UITextField,否则我不希望键盘出现。如何做到这一点呢?
let popup = UIAlertController(title: "My title",
message: "My message",
preferredStyle: .Alert)
popup.addTextFieldWithConfigurationHandler { (optionalTextField) -> Void in
optionalTextField.placeholder = "This is optional"
}
let submitAction = UIAlertAction(title: "Submit", style: .Cancel) { (action) -> Void in
let optionalTextField = popup.textFields![0]
let text = optionalTextField.text
print(text)
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
popup.addAction(cancelAction)
popup.addAction(submitAction)
self.presentViewController(popup, animated: true, completion: nil)