13

When a UITableViewCell is selected, voice over announces "selected", I don't want voice over to say "selected". How can i achieve this ?

Things I have tried with no success:

  • Changed the cell accessibilityHint and accessibilityLabel
  • Changed the cell selectionStyle = UITableViewCellSelectionStyleNone
  • changed the cell accessibilityTraits = UIAccessibilityTraitButton

Question:

  • I don't want voice over to say "selected" when a cell is selected. How can i achieve this ?
user1046037
  • 16,755
  • 12
  • 92
  • 138

7 Answers7

16

I asked this as a code level support issue from Apple and got the following solution which works perfectly. Use a custom subclass of UITableViewCell where you override accessibilityTraits as in the following example:

class NoTraitCell: UITableViewCell {
    override var accessibilityTraits: UIAccessibilityTraits {
        get {
            return UIAccessibilityTraitNone
        }
        set {}
    }
}
Melodius
  • 2,505
  • 3
  • 22
  • 37
0

You could try by deselecting the cell again:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
 [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Sam92
  • 45
  • 4
0

You can create custom cell class and override accessibilityTraits like this:

- (UIAccessibilityTraits)accessibilityTraits {
     return UIAccessibilityTraitButton;
}
jbouaziz
  • 1,484
  • 1
  • 12
  • 24
me11
  • 1
0

If you don't intend to use the selection feature of the tableview then don't use tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath). I know I've always used this as a "didTapOnRowAt" method, but a better way is to use willSelectRowAt:

func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
    // code for when a row is tapped
    return nil
}

The return nil means the cell won't actually be selected.

Jonathan.
  • 53,997
  • 54
  • 186
  • 290
0

What worked for me was to set the cell's accessibilityLabel to " " (empty string doesn't work) on didSelectRow(), trigger a reload, then reset accessibilityLabel on next dequeue.

0xWood
  • 1,326
  • 12
  • 15
-1

You can use accessibilityElementsHidden property for disabling voice accessibility.

If you don't want to hear a view in voice-over mode set the accessibilityElementsHidden property to true for that particular view(documentation)

In your case, for a UITableViewCell you can set it as true in tableView(_:cellForRowAt:) method

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    // write code to create cell ....
    cell.accessibilityElementsHidden = true
    return cell
}

Note: You can also set the property in awakeFromNib() method for a custom class table view cell.

arunjos007
  • 4,105
  • 1
  • 28
  • 43
-3

The only work around is prevent cell selection

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    return nil;
}

Add a Tap gesture on the cell and when the cell is tapped, do the what ever you want in cell selection inside the tap gesture.

user1046037
  • 16,755
  • 12
  • 92
  • 138
  • The proper way to solve this is to create a custom UITableViewCell and override its accessibilityTraits var as I have posted in my answer. – Melodius Mar 21 '18 at 19:38