Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom VoiceOver actions in UITableViewCell

When a UITableView is editable, its UITableViewCells allow the user to perform custom actions when VoiceOver is on. The user can hear the available actions by swiping up or down while the VoiceOver cursor is on the cell and then invoke the actions by double tapping anywhere on the screen. There are only two actions available in my cells: Delete (invokes the usual cell deletion) and Default (invokes a tap on the cell). My question is two-fold:

Is there a way of adding custom VoiceOver actions to a cell?

By default the Delete action is read out as "Delete" even if the table view delegate returns a custom title in the tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: method. How can I make VoiceOver read out a custom action title?

like image 730
Alexey Blinov Avatar asked May 01 '13 10:05

Alexey Blinov


2 Answers

There is simply no API for supplying custom element actions to VoiceOver. No UIAccessibility* protocol provides anything for this to be possible. I guess you should file a radar if you need to add custom actions and hope Apple will implement it in some future version of iOS (or that it will appear in iOS 7 in a month).

UPDATE: As of iOS 8, you can set/implement the accessibilityCustomActions property to return an array of your UIAccessibilityCustomAction objects (note that VoiceOver will still add the "Activate Item" default action in its UI in addition to what you provide.):

self.accessibilityCustomActions = [
    UIAccessibilityCustomAction(name: NSLocalizedString("Close", comment: ""), target: self, selector: "didPressClose")
]
...
@objc
func didPressClose() -> Bool {
    ...
}

As usual with Swift and selectors, don't forget to add the @objc attribute to the target method of the custom action in Swift if you don't subclass NSObject/the method is private, otherwise on attempting to activate the action with VoiceOver, it will not do anything and play the "end of bounds reached" sound (at least on iOS 8.2 and 8.3 where I tested with target object that did subclass NSObject).

Regarding your second question - feels like a bug which you can again file a radar for :-)

like image 122
Boris Dušek Avatar answered Oct 10 '22 02:10

Boris Dušek


iOS 8 added support for app-defined custom actions. From UIAccessibility.h:

/*
 Return an array of UIAccessibilityCustomAction objects to make custom actions for an element accessible to an assistive technology.
 For example, a photo app might have a view that deletes its corresponding photo in response to a flick gesture.
 If the view returns a delete action from this property, VoiceOver and Switch Control users will be able to delete photos without performing the flick gesture.
 default == nil
 */
@property (nonatomic, retain) NSArray *accessibilityCustomActions NS_AVAILABLE_IOS(8_0);
like image 28
jszumski Avatar answered Oct 10 '22 01:10

jszumski