Search code examples
iphoneiosipadaccessibilityvoiceover

How to make a table view based selector control accessible for VoiceOver?


I have a selector control in my app based on UITableView. The user can scroll the table view and a marker in the center shows selected item. Every selectable item is a table view cell.

Example

Now I want to make my app VoiceOver compatible for a friend. But this control, I have trouble make it work.

With VoiceOver on, I can't scroll the table view to select other elements. I looked at picker view in clocks app. It does not scroll too. But when you flick up or down it jumps to the next or previous value. It says

"swipe up or down with one finger to adjust the value".

I read Matt Gammell's VoiceOver guide where he sais the hint must say what the control does not what you should do.

So I infer this is a special trait they use for things that can swipe up or down to adjust value. But I cant find such trait.

Since UIPickerView is based on UITableViews how did Apple make it work with VoiceOver? Must I use gesture recognizer for flick?

Edit

I am setting the adjustable trait on the UITableView subclass like this:

self.isAccessibilityElement = YES;
self.accessibilityLabel = @"Start date.";
self.accessibilityTraits = UIAccessibilityTraitAdjustable;

The table view implements

- (void)accessibilityIncrement {
    NSLog(@"accessibilityIncrement");
}

- (void)accessibilityDecrement {
    NSLog(@"accessibilityDecrement");
}

Now I can drag across cells and VoiceOver will read their labels and mark them with the black rectangle. But table view does not scroll and the methods above don't get called.

The cells themselves are isAccessibilityElement = NO; and don't implement accessibility action methods.


Solution

  • You are looking for the adjustable trait: UIAccessibilityTraitAdjustable.

    If you specify this trait on your view/cell you must also implement accessibilityIncrement and accessibilityDecrement in that view/cell. These are the two methods that get called when the user swipes up and down with one finger.

    There is no need to implement any gesture recognizers yourself. Setting the trait is enough to get that behavior (it will also add the "swipe up or down with one finger ..." description)