Swift: Insert Alert Box with Text Input (and Store Text Input )

后端 未结 3 621
一个人的身影
一个人的身影 2021-02-12 23:18

In one of my viewController, I want to make an alert box appear that prompts the user to type this information.Then, I want the user to st

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-12 23:59

    In swift 3

    let alertController = UIAlertController(title: "SecureStyle", message: "SecureStyle AlertView.", preferredStyle: UIAlertControllerStyle.Alert)
    alertController.addTextFieldWithConfigurationHandler { (textField : UITextField) -> Void in
                textField.secureTextEntry = true
                textField.placeholder = "Password"
            }
    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (result : UIAlertAction) -> Void in
                print("Cancel")
            }
    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in
                print(alertController.textFields?.first?.text)
            }
    alertController.addAction(cancelAction)
    alertController.addAction(okAction)
    self.presentViewController(alertController, animated: true, completion: nil)
    

提交回复
热议问题