Ich habe eine UIAlertController
(Alert-Stil) in Swift und alles funktioniert gut. Die UITextField
, die ich hinzugefügt habe, ist jedoch ein optionales Feld, in das der Benutzer keinen Text eingeben muss. Das Problem ist, wenn ich diese UIAlertController
zeige, erscheint die Tastatur gleichzeitig mit dem standardmäßig ausgewählten Textfeld. Ich möchte nicht, dass die Tastatur angezeigt wird, außer der Benutzer tippt auf UITextField
. Wie kann das gemacht werden?verhindern, dass Tastatur automatisch mit UIAlertController
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)
müssen Sie woanders becomeFirstResponder nennen werden, zu machen. Oder Sie können self.view endEditing aufrufen: JA, nachdem/bevor Sie den Alarm anzeigen. –