Reputation: 700
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.
Upvotes: 1
Views: 6758
Reputation: 3
Return key Action which textfield you want to resign
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[self.yourTf resignFirstResponder];
}
Upvotes: -1
Reputation: 27438
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.
Upvotes: 8
Reputation: 7549
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
}
Upvotes: 0