Search code examples
iphoneobjective-cuitableviewuitextfieldfirst-responder

Tell any UITextField to dismiss


How can I tell the current firstResponder to resign? I have a UITableView with a bunch of TextFields and I don't know which is active at all times. I thought about storing pointers to all cells in an array and iterating through it, telling every cell to resignFirstResponder but I'm sure there is an easier way. Maybe something like [CurrentFirstResponder resignFirstResponder]?

I would appreciate some help, Fabian

EDIT: I don't want to dismiss the keyboard when the user taps done. It should be dismissed programmatically. Since I don't know which UITextField is active at any time, I am searching for something that calls resignFirstResponder on the current FirstResponder.


Solution

  • You could keep a reference to the UITextfeild that's actively editing using textFieldDidBeginEditing: on the UITextFieldDelegate Protocol or you could do this with your parent view:

    UIView * myParentViewView;//view containing one or more editable UI controls 
    [myParentViewView endEditing:YES];