How to add a TextField to UIAlertView in Swift

前端 未结 10 1096
耶瑟儿~
耶瑟儿~ 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:21

    In Swift 3

        let alert = UIAlertController(title: "Alert Ttitle", message: "Alert Message", preferredStyle:
            UIAlertControllerStyle.alert)
    
        alert.addTextField(configurationHandler: textFieldHandler)
    
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler:{ (UIAlertAction)in
    
    
        }))
    
        self.present(alert, animated: true, completion:nil)
    

    func textFieldHandler(textField: UITextField!)
        {
            if (textField) != nil {
                textField.text = "Filename"
            }
        }
    

提交回复
热议问题