简体   繁体   English

AlertView之前未关闭键盘

[英]Keyboard not being dismissed before alertview

I have a form, there are two fields, one is a text input, the other triggers a date picker to appear. 我有一个表单,有两个字段,一个是文本输入,另一个触发日期选择器出现。

When editing the text field, the keyboard is on screen, when I press to display the date picker in the field below the keyboard remains on screen despite my attempts to suppress it. 编辑文本字段时,键盘在屏幕上,当我按下以显示日期选择器时,尽管我试图抑制它,但键盘下方的字段仍在屏幕上。

TL;DR TL; DR

 self.view.endEditing(true)

Isn't dismissing the keyboard 不解雇键盘

@IBAction func actDroppedOff(_ sender: Any) {
    dismissKeyboard()

    self.view.endEditing(true)

    DatePickerDialog().show("Select Picked Up Date", doneButtonTitle: "Finished", cancelButtonTitle: "Cancel", datePickerMode: .date) {
        (date) -> Void in
        if let dt = date {
            let formatter = DateFormatter()
            formatter.dateFormat = "MM'-'dd'-'yyyy"
            self.txtDroppedOff.text = formatter.string(from: dt)

        }

    }
}

在此处输入图片说明

您可以调用textfield.resignFirstResponder()将键盘关闭

self.view.endEditing(true) should dismiss the keyboard for you. self.view.endEditing(true)应该为您关闭键盘。 I'm not sure why you are calling dismissKeyboard() before that? 我不确定为什么要在此之前调用dismissKeyboard() What's in that function? 该功能是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM