3

A general strategy that I use to treat both an entire UIView as an accessibility element in addition to some of its subviews is to use the UIView's contentView as an accessibility element in place of the UIView itself. E.g.,

isAccessibilityElement = false
contentView.isAccessibilityElement = true
contentView.accessibilityLabel = "super view"
subview1.accessibilityLabel = "subview1"
subview2.accessibilityLabel = "subview2"
accessibilityElements = [contentView, subview1! subview2]
   

This works well most of the time, but creates issues when the view is UITableViewCell. Basically, if isAccessibilityElement = true then when a VoiceOver user is flicking through the cells, and the lowest visible cell on screen is in focus, the tableView will autoscroll to next cell. But if the cell itself is an accessibility element, it cannot have subview which are also accessibility elements.

On the other hand, if isAccessibilityElement = false the autoscrolling becomes erratic, often with focus jumping from the lowest visible cell to the scrollbar or accessibility elements below the tableView. It seems to depend on screen size as it autoscrolls with the focus change cleanly on some devices.

I've experimented with scrolling the tableView programmatically in response to focus changes in the cells, but this also seems to result in erratic focus jumps.

Is there anyway to ensure clean VoiceOver scrolling in a UITableView while allowing cells and subviews of those cells to be treated as accessibility elements?

c_booth
  • 2,185
  • 1
  • 13
  • 22
  • Something very similar is happening for me as well, although I am am not setting my contentView as isAccessibilityElement = true. I'm just setting the cell as isAccessibility=false and then setting the cell's accessibilityElements = [ordered subviews]. This is crazy and I can't understand how others aren't having this problem. – vm2000 Oct 28 '20 at 23:44
  • I'm getting very similar behaviour with scrolling at the bottom sometimes working and sometimes not and some weird jumps when going through with VoiceOver beyond the first page (after manually scrolling) like in this question: https://stackoverflow.com/questions/64582943/ios-uitableview-accessibility-order-is-wrong-after-setting-accessibilityelements – Joseph Lord Jul 30 '21 at 17:20
  • @JosephLord were you able to fix the weird jumps issue in tableview? – cherry_4 Mar 28 '22 at 09:34
  • I believe so. See my answer. – Joseph Lord Mar 28 '22 at 14:03

2 Answers2

0

I was having these issues and worse until I made sure one of the accessibilityElements I set wasn't hidden. That element was the leftmost item (though as an info button I ordered the elements so that it came after the main cell title label).

Not promising it will fix it for anyone else but definitely worth having a test with none of the accessibility items hidden.

Joseph Lord
  • 6,446
  • 1
  • 28
  • 32
-1

You can set tableViewCell.accessibilityElements = [view1, view2].

Alex Walczak
  • 1,276
  • 1
  • 12
  • 27
  • The question already states that they are setting accessibilityElements = [contentView, subview1! subview2] on the table view cell. – vm2000 Oct 28 '20 at 23:45
  • Of course, and that’s incorrect. My answer should work, if it doesn’t please comment again – Alex Walczak Oct 30 '20 at 05:32
  • It does not work for me. Whether including or excluding contentView from the accessibilityElements, voiceover still reads my table cells in a crazy order. – vm2000 Nov 02 '20 at 15:28
  • If that is so, you can expose custom actions on the cell as a workaround (where such custom actions would make sense) – Alex Walczak Nov 03 '20 at 20:49