iOS Accessibility for CollectionView in a TableViewCell
Asked Answered
D

2

10

I'm currently working on the accessibility of our project, and here is UICollectionView that is put into a custom UITableViewCell. This CollectionView has tens of cells that are arranged in multiply rows rather than one row.

It raises an issue that when you have voiceOver on and move the focus between the collectionViewCells by swiping left or right, the system thought you are swiping between tableViewCells, since collectionView is in the tableView, and the contentOffSet of the tableView will be changed according to the tableViewCell size, instead of the collectionViewCell size.

CollectionView is already put in the the tableView and I don't think I can change this. So just wondering has anyone met this case before and is there anyway to make the collectionView accessible as normal?

Denoting answered 25/2, 2016 at 21:7 Comment(1)
You will need to provide more details to get a concrete answer to this question. However, a generic answer is to look into the UIAccessibilityContainer protocol, which exists just for this type of scenario.Binal
P
22

This is a known bug in Apple's SDK (sorry, I don't have a bug report reference) when nesting a collectionView inside a tableView. After some experimentation, I was able to work around it by using a UIView as a wrapper for my collectionView before adding it to my UITableViewCell's .contentView

    UIView *wrapperView = [[UIView alloc] initWithFrame:cell.contentView.bounds];
    wrapperView.accessibilityElements = @[collectionView];
    [cell.contentView addSubview:wrapperView];
    [wrapperView addSubview:collectionView];
Pinkston answered 5/8, 2016 at 22:15 Comment(3)
You can also just manually set this on the UITableViewCell itself with the collection view and other top-level items you may have in the table cell (title for example).Finespun
Good point with the .accessibilityElements = @[collectionView];.Galenism
You don't need the wrapper view. tableViewCell.accessibilityElements = [tableViewCell.collectionView] is enough.Stansbury
D
0

Just fix the problem by reconstructing the whole page, here are 2 things do not do to make your app more accessible:

  1. Avoid adding a subview directly to the tableView/collectionView like

    [tableView/collectionView addSubview:yourSubView];

  2. Avoid adding a vertically scrollable collectionView to a tableViewCell.

    Adding a horizontally scrollable collectionView to a tableViewCell seems will not cause any issue.

Denoting answered 16/3, 2016 at 18:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.