Understanding system logic for the first responder

I am confused about the individual answer points:

  • If I call - becomeFirstResponder , does the system call – canBecomeFirstResponder ? Why?
  • Why are there - becomeFirstResponder and – canBecomeFirstResponder ? In what situations can they return different values?
  • Does the application require a first responder each time? If so, what happens when I call – resignFirstResponder on some object? Does UIApplication first responder immediately or is it a β€œtoken” thrown at some point in the responder chain? Can I call - becomeFirstResponder object when I want to get rid of this pilgrim token?
  • ...

Please explain to me how the system manages its first responder. What happens under the hood when an object becomes the first responder, and when the first responder resigns. What challenges does the system make ... Thank you!

+8
ios objective-c cocoa-touch first-responder uiresponder
source share
1 answer
  • The default implementation of becomeFirstResponder makes a call to canBecomeFirstResponder . This is because the responder that returns NO from canBecomeFirstResponder does not have to be the first responder.
  • becomeFirstResponder will make the receiver actually the first responder if it succeeds. canBecomeFirstResponder just checks to see if the receiver wants to be the first responder without changing anything. It is possible that becomeFirstResponder could fail if the current first responder refuses to resign. There may be other situations in which becomeFirstResponder may also fail.
  • There should not be anything in your code that has the first status of the responder. Judging by the private method UIResponder firstResponder , in this case, the system does not assign any specific value.

Basically, when someone wants to become the first responder, the current first responder (if any) will be asked to resign, and then the new facility will become the first responder. This may cause the system to display an on-screen keyboard or take some other action. When the first responder resigns, this may cause the system to hide the on-screen keyboard or take some other action.

When an event without a touch arrives, it is first delivered to UIWindow. UIWindow delivers it to the first responder. The documentation does not seem to indicate whether UIWindow is trying to process the event itself (and pass it to UIApplication, as usual if it does not handle it) or simply ignore the event if there is no first responder.

See the documentation for more details.

+6
source share

All Articles