VoiceOver 读了两次 table header 并且总是添加单词 "heading"

VoiceOver reads table header twice and always adds the word "heading"

这是我的代码:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return self.setupFriendsHeaderView()
}

func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    view.accessibilityTraits = .none
    for subView in view.subviews {
        subView.accessibilityTraits = .none
    }
}

func setupFriendsHeaderView() -> UIView? {
    let view = UIView(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: tableView.frame.width, height: 44)))

    view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.switchPendingRequestsStatus)))
    view.isAccessibilityElement = true
    view.accessibilityLabel = "Pending requests"

    return view
}

当您第一次点击 header 时,VoiceOver 会说:"Pending requests. Pending requests header." 有时它无法完成第一个句子并开始说出下一个句子。第二次它只是说 "Pending requests header." 我需要它做的是说 "Pending requests" 一次,而不是 "heading"。 我看到建议使用 willDisplayHeaderView 方法的答案,但它根本没有帮助。

如果您想使用 VoiceOver 从不说 "header" 显示带有 header 部分的 table 视图,请忘记它:那是死胡同 ⟹ 当前 没有解决方案来完成这种table视图设计。

实现技术目标的最佳方法是创建一个 table 视图,其部分 header 是具有不同外观的单个单元格 ⟹我指定 "technical" 是因为,从功能上讲,这绝对不适合 VoiceOver 用户,也不 recommended

确实,header 部分是重要的标记,不仅可以分隔特定的信息块,还可以让 由于转子,可以非常快速地从一个部分移动到另一个部分。

我猜你的目的可能纯粹是视觉上的,因为从功能上讲,它无法得到任何辅助功能专家或 VoiceOver 用户的认可

和你一样,我花了很多时间尝试找到解决这个问题的技术"problem"但是,即使我找到了它(不幸的是我没有),我绝对不会实施它。

========== 编辑 ==========

在您发表评论 (07.25.2019) 后,我现在明白您的问题是阅读了两次的标题,而不是删除 'header' 特征的意愿.

我创建了一个空白项目,我在其中实现了下面的代码片段,以获得一个 table 视图,其中 header 永远不会重复两次:

class SimpleHeadersTableViewController: UITableViewController {

    override func numberOfSections(in tableView: UITableView) -> Int { return 4 }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 5 }

    override func tableView(_ tableView: UITableView,
                            viewForHeaderInSection section: Int) -> UIView? {

        let headerView = UIView(frame: CGRect(origin: CGPoint.zero,
                                              size: CGSize(width: tableView.frame.width,
                                                           height: 44)))

        let a11yHeader = UIAccessibilityElement(accessibilityContainer: headerView)
        a11yHeader.accessibilityFrameInContainerSpace = headerView.frame

        a11yHeader.isAccessibilityElement = true
        a11yHeader.accessibilityLabel = "Pending requests"
        a11yHeader.accessibilityTraits = .header

        headerView.accessibilityElements = [a11yHeader]

        return headerView
    }


    override func tableView(_ tableView: UITableView,
                            cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "cellId",
                                                 for: indexPath)
        cell.textLabel?.text = String(indexPath.row)

        return cell
    }
}

试一试并根据您的应用程序进行调整。

现在,VoiceOver 读取 table header 一次,并始终添加“标题”一词

我在使用带有自定义 UILabel 的自定义 UITableViewHeaderFooterView 时遇到了这个问题。我发现将 headerfooterview 的 accessibilityLabel 设置为此自定义标签的文本可以解决问题。

宣布“标题”背后的原因是 UITableView 向 header 视图添加了 header 特征。为了避免这种情况,只需简单地从 UITableViewHeaderFooterView 子类化并用这样的空特征覆盖 accessibilityTraits

override var accessibilityTraits: UIAccessibilityTraits {
  get { [] }
  set { }
}