Reputation: 35
In Cocoa, how do you define a class that sends an action? I want to be able to connect the action to the selector of another object in IB in the style of NSButton. I would prefer not to subclass NSControl if possible.
Upvotes: 1
Views: 502
Reputation: 96393
id
, for the target. I'm not sure whether this should retain or not; I'd say no, since the target will normally be the controller that owns the window that (indirectly) owns the view.SEL
, for the action.mouseUp:
and keyDown:
(checking that the key in question is the space bar or return or enter) by sending yourself an accessibilityPerformAction:
message, passing NSAccessibilityPressAction
.accessibilityPerformAction:
message by either sending your action message to your target (NSAccessibilityPressAction
) or calling up to super
(other), as described in the documentation for that method.You should also implement the rest of the NSAccessibility protocol while you're at it. Test that work with a mix of the Accessibility Inspector and VoiceOver.
Upvotes: 2