I am confused about the iPhone responder chain. Specifically, in the iPhone event handling guide http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html, we have the following:
The first responder is the responder object in an application (usually a UIView object) that is designated to be the first recipient of events other than touch events.
But UIView is a subclass of UIResponder. And the UIResponder class reference says this:
- (BOOL)canBecomeFirstResponder
Return Value
YES if the receiver can become the first responder, NO otherwise. Discussion
Returns NO by default. If a responder object returns YES from this method, it becomes the first responder and can receive touch events and action messages. Subclasses must override this method to be able to become first responder.
I am confused by the apparent contradiction. Can anyone clear it up for me?
For what it's worth, I did set up a simple view-based application, and call canBecomeFirstResponder and isFirstResponder on its view. Both returned NO.
Press the iPhone's Home button to access the lock/passcode screen. Tap the Emergency button in the lower left-hand corner. Tap the red Medical ID button in the lower left-hand corner of the Emergency keypad screen. You'll be taken to the Medical ID screen.
Open the Health app and tap your profile picture . Tap Medical ID. Tap Edit, then scroll to Emergency Contacts. Tap the Add button to add an emergency contact.
In case of an emergency… People will still not be able to access your iPhone without entering your passcode, nor can they make calls using your phone. Furthermore, the information you add to your Medical ID is not shared with other apps. However, the Medical ID can be accessed even while the phone is locked.
The nomenclature can be confusing. Instead of "first responder" think of it as "initial event target" i.e. the object that is the first responder becomes the initial target for all events. In some APIs this is also called the "focus" although in the Apple APIs that is usually reserved to describe windows.
At any given time, there is only one first-responder/intial-event-target in the app. Only individual objects/instances can become a first-responder/intial-event-target. Classes can merely define if their instance have the ability to become a first-responder/intial-event-target. A class need only provide the ability to become the app's first-responder/intial-event-target if it make sense to do so. For example, a textfield obviously needs the ability to trap events so that it can use those event to edit itself. By contrast, a static label needs no such capability.
Whether a particular class inherits from NSResonder has no bearing on whether the class (or a specific instance of the class) will let itself be set as the first-responder/intial-event-target. That ability comes solely from the instances' response to the canBecomeFirstResponder
message. The same instance can refuse to be the first-responder/intial-event-target under one set of conditions and then allow it later when conditions change. Classes can of course hardwire the status if they wish.
In other words, first-responder/intial-event-target is a status of a particular instance at a particular time. The first-responder/intial-event-target is like a hot potato or a token that is handed off from instance to instance in the UI. Some classes refuse to grab the hot potato at all. Some always do and others grab it sometimes and ignore it others.
What this means is that the basic UIView is not able to become first responder - it doesn't do anything with motion events, editing-menu messages, etc.
Some UIView subclasses (like UITextView) are able to become first responder, and you can write your own UIView subclass that does so too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With