简体   繁体   中英

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

 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. I'm not sure why you are calling dismissKeyboard() before that? What's in that function?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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