How to add a TextField to UIAlertView in Swift

前端 未结 10 1119
耶瑟儿~
耶瑟儿~ 2020-12-23 13:41

I have this code, but I dont know how to show a textfield inside the UIAlertView.

var altMessage = UIAlertController(title: \"Warning\", message: \"This is A         


        
10条回答
  •  渐次进展
    2020-12-23 14:31

                var inputTextField: UITextField?
    
                //Create the AlertController
                let actionSheetController: UIAlertController = UIAlertController(title: "Rename", message: "", preferredStyle: .Alert)
    
                //Create and add the Cancel action
                let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
            //Do some stuff
                }
                actionSheetController.addAction(cancelAction)
                //Create and an option action
                let nextAction: UIAlertAction = UIAlertAction(title: "OK", style: .Default) { action -> Void in
            //Do some other stuff
                }
                actionSheetController.addAction(nextAction)
                //Add a text field
                actionSheetController.addTextFieldWithConfigurationHandler { textField -> Void in
            // you can use this text field
            inputTextField = textField
                }
    
                //Present the AlertController
                self.presentViewController(actionSheetController, animated: true, completion: nil)
    

提交回复
热议问题