Retired Document
Important: This document describes the old, key-based accessibility API. The use of this API is discouraged. Use the new, method-based API instead. For more information on the new accessibility API, see Accessibility Programming Guide for OS X.
Supporting Actions
NSAccessibility defines three methods for accessing an object’s actions:
accessibilityActionNames
accessibilityActionDescription:
accessibilityPerformAction:
The first method returns an array of action names supported by the accessibility object, the second returns a localized string describing a particular action, and the third performs a particular action.
When supporting an action in a subclass, you need to override all three methods. In the accessibilityActionNames
method, you need to invoke the superclass’s implementation and append your new action. This allows an assistive application to get an accurate list of all actions you support. In the other two methods, compare the action name to those your subclass supports; if no match is found, invoke the superclass’s implementation. Listing 1 shows sample implementations of these methods that add a new action named @"Boing"
.
Listing 1 Supporting a new action
static NSString *MyBoingActionName = @"Boing"; |
- (NSArray *)accessibilityActionNames |
{ |
static NSArray *actions = nil; |
if (actions == nil) { |
actions = [[[super accessibilityActionNames] |
arrayByAddingObject:MyBoingActionName] retain]; |
} |
return actions; |
} |
- (NSString *)accessibilityActionDescription:(NSString *)action |
{ |
if ( [action isEqualToString:MyBoingActionName] ) |
return NSLocalizedString(@"BoingDescription", |
@"Performs the Boing action"); |
else |
return [super accessibilityActionDescription:action]; |
} |
- (void)accessibilityPerformAction:(NSString *)action |
{ |
if ( [action isEqualToString:MyBoingActionName] ) |
[self doBoing]; |
else |
[super accessibilityPerformAction:action]; |
} |
When performing an action, the subclass’s implementation ideally should invoke the same methods that are invoked if the action is performed directly from the user interface.
Copyright © 2004, 2015 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2015-03-09