It really depends on the architecture of your application. As a rule, perform actions wherever they make sense. An action reporting responder chain helps you in this regard.
If your application is not document-based, the response chain for activity messages is as follows:
- Whatever the defendant is the first defendant
- View Hierarchy
- Window
- Window controller
- Window delegate
NSApp- Application delegation
I only use actions in the application’s deletion if they are truly global for the entire application. Otherwise, I put them in a window controller (which is usually a window delegate) if they make sense for a specific window or view controller if they make sense for a specific view.
It is worth noting that view controllers (subclasses of NSViewController ) arent automatically inserted into the responder chain. I do this manually after adding the appropriate view to the supervisor. For example, in a subclass of NSViewController :
NSResponder *nextResponder = [[self view] nextResponder]; [[self view] setNextResponder:self]; [self setNextResponder:nextResponder];
Inserts self (an instance of a subclass of NSViewController ) into the responder chain between the view and the original views of the next responder.
Note that there is nothing wrong with your third approach, namely the presence of a specific purpose for (a subset) of activity messages. A responder chain exists to enable various entities to process action messages because some actions may be context sensitive. For example, the actions in the File menu usually apply to the window, which is currently the main window, so it makes sense to not have a specific purpose and instead use a chain of responders. On the other hand, the actions in the ApplicationName menu are really global - they don’t need to go through the chain of responders, so you can connect them to a specific target.
user557219
source share