2

I have checked every possible thread before posting this question but couldn't find a good solution.

I have 5 textfields in my view, when selected the first 2 a keyboard should appear and when selected the last 3 my PickerView should appear. Everything works fine as I have used tags to identify my textfields and in the "textFieldShouldBeginEditing" I returned False for my last 3 textfields.

HOWEVER if I selected text field 2 and then move to text field 3,keyboard will appear OVER the picker view. I have tried using textFieldDidEndEditing but it didn't work.

Is there any other approaches to solve this problem?

I use addTarget on each textfield to call this function

func openDatesPicker() {

    ActionSheetStringPicker.show(withTitle: "Appointment Date", rows: datesArray , initialSelection: selectedDateIndex , doneBlock: {
        picker, value, index in
        self.selectedDateIndex = value
        if let selected = index as? String{
            self.dateTF.text = selected
            let timeIndex = self.findEarliestTime(date: self.dateTF.text!)
            self.timeTF.text = timeIndex

        }

        return
    }, cancel: { ActionStringCancelBlock in return }, origin: self.view)

}
12
  • How are you showing the picker views? Commented Aug 19, 2017 at 1:37
  • Im using a custom picker viewer i found on GitHub , its called "ActionSheetPicker_3_0" Commented Aug 19, 2017 at 1:38
  • But how are you showing the picker view? What makes it appear on the screen? Commented Aug 19, 2017 at 1:51
  • I updated my question @rmaddy Commented Aug 19, 2017 at 2:25
  • Have you tried using resignFirstResponder() ? Commented Aug 19, 2017 at 3:09

2 Answers 2

2

Please add this statement in the beginning of your openDatesPicker method

self.view.endEditing(true)

According to documentation:

This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to true, the text field is never even asked; it is forced to resign.

Sign up to request clarification or add additional context in comments.

Comments

0

just set last 3 textfields inputView as pickerView .No need to returned False or do different code for last 3 textfields.It will work fine.

 textfield.inputView = pickerView

1 Comment

The problem is that i don't have a pickerView. Im using a custom PickerView and it doesn't have a view variable

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.