9

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?

Alexey Blinov
  • 1,684
  • 3
  • 17
  • 25

2 Answers2

12

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 :-)

Boris Dušek
  • 1,272
  • 11
  • 12
  • Is there a way to customise the wording of default action? "activate item" is not really helpful. – wangii Jan 29 '16 at 10:08
  • 2
    No, as there is no API for this (it is also not possible to customize the default hint about availability of custom actions, i.e. the "Swipe up or down ..."). – Boris Dušek Jan 29 '16 at 10:26
  • Just a thought but have you tried removing traits? For instance, try removing the 'Button' trait and see if that helps. (I'm away from my computer now or I'd test it myself.) – Mark A. Donohoe Sep 20 '16 at 17:14
  • did you manage to fix this issue? Using @BorisDušek solution I am able to hear with the VoiceOver and I can select the action but I cannot actually delete a cell using it. the reason is that I cannot pass the indexPath.row using the #selector .. Please let me know if you got any solution – Pavlos Feb 12 '18 at 11:47
  • In case someone else can't get this working at first: When implementing this, make sure that your target method returns a boolean. Otherwise it won't work. – Adrian Schönig Apr 05 '19 at 18:05
3

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);
jszumski
  • 7,430
  • 11
  • 40
  • 53