iOS Accessibility for CollectionView in a TableViewCell

天大地大妈咪最大 提交于 2019-12-04 07:24:23

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];

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!