Παρασκευή, 30 Μαρτίου 2012

What’s this resignFirstResponder business?

Follows section from The Big Nerd Ranch Guide - Objective C: 

Some view objects are also controls - views that the user can interact with. 
Buttons, sliders and text fields are examples of controls. 

When there are controls on the screen, one of them can be the first responder

Having first responder status means that the control gets dibs on handling any text input from the keyboard or any shake events (such as “Shake to Undo”).

When the user taps a control that can accept first responder status, that control is sent the becomeFirstResponder message. Until another control becomes the first responder or the current control is sent the resignFirstResponder message, that control will keep this status and receive keyboard and shake input. 

When a text input control (like a text field) becomes the first responder, the keyboard materializes on the screen. As long as the current first responder is a control that accepts text input, the keyboard will remain on the screen. 

At the end of addTask:, we tell the text field to resign its status , which causes the keyboard to dematerialize. 

[taskField[resignFirstResponder];


image from documentation

Documentation:
A view that is first responder accepts key events and action messages before other objects in a window. It also typically takes part in the key loop (see“Keyboard Interface Control”). By default, view objects refuse first-responder status by returning NO in acceptsFirstResponder. If you want your custom view to respond to key events and actions, your class must override this method to return YES:
- (BOOL) acceptsFirstResponder{
return YES;
}

2 σχόλια:

  1. I have looked into many tutorials and helps on First Responder concept but this was the only one which actually made any sense and I got it FINALLY!

    ΑπάντησηΔιαγραφή