views:

87

answers:

2

I want a UITextField to be sent the resignFirstResponder message if it is being edited and a user touches elsewhere on the screen. Since there are several text fields I need a way to programmatically determine which one is the first responder to send it the message. How can I do this? Is there some sort of global first responder object?

Thanks, Jacob

A: 

UITextField inherits from UIResponder so you can use isFirstResponder (which returns a BOOL) to query it.

if ([myTextField isFirstResponder]) {
    // do stuff
}
nevan
Let's say a user is editing a UITextField in a UITableViewCell and he taps the background in another UITableViewCell. That UITableViewCell has no access to its sibling UITableViewCells, so I would have to pass a message up to a parent view to pass another message back down to all the cells. Is this what you recommend?
Jacob Lyles
A: 

The simplest way is to find the first responder and tell it to resignFirstResponder.

rpetrich