How to dismiss an UIAlertController and the keyboard simultaneously?

后端 未结 8 1252
离开以前
离开以前 2021-02-05 13:04

I have created a signup form with a UIAlertController and used the method addTextFieldWithConfigurationHandler to add a text field. But there is a litt

8条回答
  •  臣服心动
    2021-02-05 13:41

    Swizzle viewWillDisappear method for UIAlertController, and perform resignFirstResponder on correspodent text field or call endEditing: on controller's view

    I am using for this ReactiveCocoa:

            let alert = UIAlertController(title: "", message: "", preferredStyle: .Alert)
    
            alert.addTextFieldWithConfigurationHandler {
               textField in
            }
    
            let textField = alert.textFields!.first!
    
            alert.rac_signalForSelector(#selector(viewWillDisappear(_:)))
                 .subscribeNext {
                     _ in
                     textField.resignFirstResponder()
                 }
    

提交回复
热议问题