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

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
Jacob Lyles
  • 9,920
  • 7
  • 32
  • 30

2 Answers2

0

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

if ([myTextField isFirstResponder]) {
    // do stuff
}
nevan king
  • 112,709
  • 45
  • 203
  • 241
  • 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 Aug 07 '10 at 23:13
0

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

Community
  • 1
  • 1
rpetrich
  • 32,196
  • 6
  • 66
  • 89