ios - 无障碍列表读取 iOS Swift
问题描述
有什么方法可以让 tableview 在将全部注意力集中在 tableview 上的同时读取为可访问性列表?例如:我有一个类似的列表
- 艺术
- 球
- 车
- 狗
因此,我希望可访问性阅读器阅读为“第 1 项,共 4 项艺术,第 2 项,共 4 项球,......等”
解决方案
是的,你可以,但你必须手动实现。
您可以为您的单元创建某种模型,用于配置它。您需要将表格视图的总行数传递给每个单元格的配置。
struct CellConfig {
let title: String
private let count: Int
init(title: String, count: Int) {
self.title = title
self.count = count
}
}
CellConfig
您可以通过像这样传递当前来扩展功能以让返回正确的可访问性标签IndexPath
:
struct CellConfig {
...
func axLabel(for indexPath: IndexPath) -> String {
let currentElement = indexPath.row + 1
return "Item \(currentElement) of \(count). \(title)."
}
}
因此,当从您的委托方法返回您的单元格时:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard indexPath.row < items.count else { return UITableViewCell() }
let item = items[indexPath.row] // The array here holds all the configs of every cell.
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as? UITabelViewCell
cell?.titleLabel.text = item.title
cell?.accessibilityLabel = item.axLabel(for: indexPath)
return cell ?? UITableViewCell()
}
推荐阅读
- oracle - 将语句级触发器转换为行级触发器
- jenkins - 通过 Jenkins 连接 Git 存储库抛出 Permission Denied 错误
- javascript - 使用 amCharts 执行事件侦听器 clickGraphItem 时如何引用 JavaScript 对象数组中的变量
- ios - WKWebView 的 WKUrlSchemeHandler 和带有 Secure 属性的 Cookies
- reactjs - 构建 Reacjs 项目后不透明度值更改为 1%
- powershell - 如何在 Powershell 中对字符串进行 hash256 和数字签名(使用私钥)
- php - 错字3 tt_news 配置列表模板
- apache-kafka - 同一 Kafka 主题的多个 Flink 管道
- vue.js - 在 Vue.js 中进行样式设置的最佳且简单的方法是什么?我可能认为引导程序是最好的选择
- wordpress - Wordpress:如何只允许特定角色进行一些评论操作(删除、编辑...)?