How can you set the accessibility of subviews of UITableViewCells individually.
It should not be accessible as complete cell?
Contibuting to answer of @ma11hew28, here is another way to do that saves some lines of code, in Swift 5:
class ServiceTableViewCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
self.selectionStyle = .none
self.isAccessibilityElement = false //not allowing accessibility for the cell itself
self.accessibilityElements = [mySubview1!, mySubview2!, mySubview3!] // but allowing accessibility in the cell's subviews
}
}
If your tableview cell consists of text only, enabling accessibility for the cell will do and it will read out the whole cell. If you have other objects and buttons, it is recommended to use a subclass of UITableViewCell
and override the -accessibilityElements
method to return all your accessible elements.
Some code:
#import "CustomCell.h"
@implementation CustomCell
- (void)awakeFromNib
{
[super awakeFromNib];
self.accessibilityElements = @[self.view1, self.label, self.imageView];
}
Following post may help:
http://cocoacaffeine.wordpress.com/2013/11/29/little-tricks-of-accessibility/
Make the cell inaccessible and your subviews accessible in tableView(_:cellForRowAt:).
isAccessibilityElement = false
mySubview1.isAccessibilityElement = true
mySubview2.isAccessibilityElement = true
mySubview3.isAccessibilityElement = true
I got stuck on this too because I (trying to be efficient) put the above in my custom cell's init(style:reuseIdentifier:) method. But, that didn't work, probably because UITableView
resets everything after initializing each of its cells.
Related: Accessibility Programming Guide for iOS: Enhance the Accessibility of Table Views
I tried every solution proposed here, but none of those solved my issue.
I was able to hide my cell from accessibility and highlight only the elements from my UITableViewCell
by setting the cell's contentView.accessibilityElementsHidden
to true and also setting my UI items isAccessibilityElement
to true.
contentView.accessibilityElementsHidden = true
UIElement.isAccessibilityElement = true