1

In my app I have a form where the user fills out his/her information, the form has some textfields and amongst those is one where the user can select their country. This textfiled is a dropdown which when active displays a dropdown (tableview) with the list of countries to select. I have created a demo project, to reproduce the issue and share it here. In this demo, I have add 3 textfields, when the user goes to the second textfiled, using the next button on the keyboard, a tableview is displayed. Now what I want to achieve is my keyboard should hide when the dropdown tableview is displayed. I have put in quite some time trying to figure this out but has no success. Here is the link to the demo project: https://github.com/tejaskutal/IQKeyboardManagerDemo

Any help is greatly appretiated.

P.S: For some weird reason, when you click next when the first textfiled is active, it jumps to the third one first and then goes to second textfield after next is clicked one more time. However, this has nothing to do with the original problem so I left it there.

Tejas K
  • 682
  • 11
  • 28

3 Answers3

8

No need to handle different delegate. In your viewDidload you can do something like,

 yourTextField.inputView = UIView.init(frame: CGRect.zero)
 yourTextField.inputAccessoryView = UIView.init(frame: CGRect.zero)

so, for that textfield keyboard or toolbar will not be appeared.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
0

You can use your UITextField's delegate and implement the textFieldShouldBeginEditing. Something like

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        if textField == theTextFieldToIgnore {
            view.endEditing(true)
            return false
        }
}

As for your textField chaining, you should implement the textFieldShouldReturn

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        if textField == firstOne {
            textField.resignFirstResponder()
            secondOne.becomeFirstResponder()
        }
        return true
    }
Shamas S
  • 7,507
  • 10
  • 46
  • 58
  • If I add `return false` in `textFieldShouldBeginEditing ` the keyword will not be shown for any textfield, right ? – Tejas K Dec 01 '17 at 06:06
  • @TejasK Yes indeed. You should use a check for that in your code, I updated my code as well. :) – Shamas S Dec 01 '17 at 06:09
  • Hi, I tried this, however this does not dismiss the keyboard shown due to the previous textfield. Request you to check the code on GitHub. – Tejas K Dec 01 '17 at 06:14
  • Ok updated the code. I just made a few incorrect assumptions. `view.endEditing(true)` will dismiss any previously open keyboard. – Shamas S Dec 01 '17 at 06:21
  • No `[self.view endEditing:YES]` is not dismissing the keyboard, that's what my problem is :( – Tejas K Dec 01 '17 at 06:24
-1

Return key Action which textfield you want to resign

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
        [self.yourTf resignFirstResponder];

}
Vinodh
  • 5,262
  • 4
  • 38
  • 68