First responder clarification

I asked a question about the application of the first responder earlier - and received the answer here:

First Responder Problem

Could someone give me a version of this "dummy"? Being new to Cocoa, I don't know where to start with one of these methods. I quickly reward answers

Zach

+6
objective-c cocoa interface-builder macos
source share
2 answers

The first responder is this.

What you are asking is target action. You have an interface object (button, menu item) in which you need to call several things, but the user interface object sends only one action.

Therefore, the solution: do this by doing a few things.

Connect the user interface object to the action method that you implement in the controller object (in your case, in the document). In this method, perform all the actions that the button should trigger.

The subclassical solution is basically the same, except that instead of connecting the user interface object to your document, you connect it to the font manager, but you also create the font manager an instance of the NSFontManager subclass that you create, not an instance NSFontManager directly. In your subclass, you override addFontTrait: and add other behavior to your implementation. At the beginning or end of this method, you send [super addFontTrait:sender] to invoke the NSFontManager implementation, so the original implementation is executed.

Itโ€™s a long paragraph, but actually it doesnโ€™t work that much: the difference is simply creating a subclass and instantiating this subclass.


You already said that the "Apple Documentation is incredibly vague," but it really is not. It just happens to be a lot, and perhaps you did not look at the necessary documents.

These are the documents you need to read, from start to finish and in order:

EDIT: This list is for Xcode 3. I posted an updated (for Xcode 4) version of this list in another answer .

There is also a User Guide for tools , but, unfortunately, it is uncertain or, to be more precise, incomplete. It does not contain much useful information, for example, how to use the Zombie template to debug crashes. This is a high-level review, nothing more.

Also add the following bookmarks:

This is a lot of reading, but it will tell you everything you need to know, and this order roughly corresponds to what you need to know.

+22
source share

Another answer says that you have two options:

First: replace the action with what you created, and then insert the original version into it. In this case, just call the appropriate NSFontManager method. That is, you add the original functionality to your own implementation of the method. In this way, both actions are performed.

Second: subclass the class in which the original functionality is implemented, and add your implementation by overriding the method called -addFontTrait . Thus, your code is launched "nearby". This question may help you find the right implementation.

So, the bottom line is that you can either add original functionality to your implementation, or vice versa. In this case, I would try the first one.

+1
source share

All Articles