How can “First Responder” be used in a xib file?

主宰稳场 提交于 2019-12-03 10:19:34

You would use First Responder as the target of an action whenever you want the action to be sent to the first responder, regardless of which particular object that happens to be at the time the action is sent.

In desktop Cocoa, a message targeted for the First Responder is in fact a nil-targeted action - no target is implicitly understood as the first possible responder, the First Responder.

Often, textual actions are directed to the First Responder. You want keypresses to be sent to whichever text field has focus, but the text field that has focus changes over the life of the view and of the application. You could manually retarget the action each time a text field get focus, but thanks to NSResponder, you don't have to bother - that's all taken care of for you.

Assigning an action to the first responder object is the same as adding an action to a control with a nil target programatically. When the action is triggered, the application will go through the responder chain and send the action to the first responder that accepts it. On the mac, it is often used to automatically send menu commands to the current window or document. You should use it if you have multiple objects which you want to send messages to with the same button.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!