5

IOS UITableView accessibility order is wrong after setting accessibilityElements on UITableViewCell

I have a large and complicated UITableView with, many different kinds of custom UITableViewCells. If I don't do any special accessibility changes to my code, the table reads all cells one after another down the screen, scrolls properly so that it continues reading until the entire table is read. However, within some cells, subviews aren't being read in the correct order. To fix this, on the UITableViewCell I set isAccessibilityElement = false and accessibilityElements = [my subviews in the correct order]. When I do this the table starts acting crazy in voice over mode.

Sometimes it will stop after a particular cell and not proceed to others on the screen.

Sometimes it will jump around from reading a cell at index 20 to reading one at index 5.

Sometimes it will get to the last cell visible on the screen (more are there to scroll to) and will jump out of the table to read "vertical scroll bar" for the table's scroll bar and then never continue with the table's content.

Again all I've done is in my UITableViewCell subclasses:

isAccessibilityElement = false 
accessibilityElements = [my subviews in the correct order]
vm2000
  • 332
  • 1
  • 14

1 Answers1

1

I had the same problem. This may happen because the subviews are added in the wrong order. This worked for me: add the following in all your UITableViewCell subclasses:

override func didAddSubview(_ subview: UIView) {
     super.didAddSubview(subview)
     self.accessibilityElements = self.subviews
}