How to add TextField to UIAlertController in Swift

前端 未结 13 735
余生分开走
余生分开走 2020-12-07 20:03

I am trying to show a UIAlertController with a UITextView. When I add the line:

    //Add text field
    alertController.addTextFie         


        
13条回答
  •  庸人自扰
    2020-12-07 20:13

    To add a text field in Swift 3.0:

    let alertController = UIAlertController(title: "Title", message: "", preferredStyle: .alert)
    alertController.addAction(UIAlertAction(title: "Save", style: .default, handler: { alert -> Void in
        let textField = alertController.textFields![0] as UITextField
        // do something with textField
    }))
    alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
    alertController.addTextField(configurationHandler: {(textField : UITextField!) -> Void in
        textField.placeholder = "Search"
    })   
    self.present(alertController, animated: true, completion: nil)
    

提交回复
热议问题