How can you set the accessibility of subviews of UITableViewCells individually.
It should not be accessible as complete cell?
-
Could you let us know what you have tried already? – Mack Mar 17 '14 at 16:29
-
@Mack: I already tried with disabling cell accessibility and enable the subviews accessibility . – SwapnilN Mar 18 '14 at 09:08
-
@SwapnilN, do it in [`tableView(_:cellForRowAt:)`](https://developer.apple.com/reference/uikit/uitableviewdatasource/1614861-tableview), not in your custom cell's [`init(style:reuseIdentifier:)`](https://developer.apple.com/reference/uikit/uitableviewcell/1623276-init) method. See [this answer](http://stackoverflow.com/a/41309150/242933). – ma11hew28 Dec 24 '16 at 00:10
4 Answers
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/

- 83
- 8

- 2,539
- 2
- 21
- 27
-
Also very helpful for UITesting... could find an element with the accessibility inspector but the UITest couldn't find the element. This solved the problem. – inf1783 Nov 08 '17 at 09:48
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

- 121,420
- 116
- 450
- 651
-
In your case was the cell created in a storyboard or nib? If so, you'd need to put that code in init?(coder:) and I think it should work. init(style:reuseIdentifier:) is not called when the cell is created from a storyboard or nib. – Mobile Dan Jan 20 '17 at 02:58
-
-
Thanks for confirming that @mattdipasquale! I am interested to know if setting accessibility properties in an init() method is problematic. I posted an answer to another question that includes setting accessibility in the init() as one of the suggested solutions. I tested setting isAccessibilityElement to true on subviews in the cell init() and don't see that it gets lost when cells are displayed initially or recycled. I may not be testing the same scenario as you. – Mobile Dan Jan 20 '17 at 03:42
-
Just to be clear, I believe this is the correct answer and that tableView(_:cellForRowAt:) is the best place to set accessibility properties on and within cells. In my testing, it appears that you could also set the properties within the init() of a custom cell. [I answered a different VoiceOver question](http://stackoverflow.com/a/41498372/2092663) where one of the solutions included setting accessibility properties in the init() method. If I confirm that this is problematic, I will update that answer and post a update here also. Thank You! – Mobile Dan Jan 20 '17 at 17:15
Contributing to the answer of @ma11hew28, here is another way of doing that saves some lines of code,
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
}
}

- 925
- 9
- 23
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