Reputation: 17530
In a special use case I want a UITableView
to be a single accessibility element instead of a container exposing its cells to VoiceOver
.
I tried setting its isAccessibilityElement
to true
and assigning its accessibilityLabel
but it didn't work.
Upvotes: 1
Views: 1146
Reputation: 5671
I want a
UITableView
to be a single accessibility element instead of a container exposing its cells toVoiceOver
.
Unfortunately, it's impossible as is.😨
You can code it with no warning because you deal with an informal protocol but it won't be interpreted by VoiceOver
: it's a mess because you do the same thing on a tableView
as on a simple label
for instance but it doesn't work here.
I have no technical proof but I think that a tableView
isn't meant to be an accessible element, only its cells should.🤔
I tried setting its isAccessibilityElement to true and assigning its accessibilityLabel but it didn't work [...] when I swipe left and right, VoiceOver goes through the cells and doesn't pronounce the table view's
accessibilityLabel
.
A UITableView
may be seen as a container inside which many elements are embedded (its cells) and, as is, you can't have simultaneously a parent view (the table view) and its child views (its cells) that are both accessible with VoiceOver: either the table view can be selected or its cells.
If you don't want to swipe through the cells, insert the code snippet hereafter:
myTableViewInsideTheCell.accessibilityElementsHidden = true
Then, VoiceOver
is informed that elements inside the table view mustn't be interpreted.
Now, as the table view can't be seen as an accessible element, just create one inside your table view cell:
let a11yElt = UIAccessibilityElement(accessibilityContainer: myTableViewCell.contentView)
a11yElt.accessibilityFrameInContainerSpace = myTableViewInsideTheCell.frame
a11yElt.accessibilityTraits = .staticText
a11yElt.accessibilityLabel = "my table view inside the cell is now accessible."
myTableViewCell.accessibilityElements = [a11yElt]
This element overlaps your table view inside the cell and can be treated as any other accessible element with the common properties. 👍
I think many other ways are possible to reach your goal but, following this rationale, you could make VoiceOver treat a UITableView as a single accessibility element.
You have the guideline, now it's up to you to implement/adapt it in your environment to reach your goal.😉
Upvotes: 1