自动化 - 如何为 ActionSheet 元素提供辅助功能标识符

Automation - How to give Accessibility identifier for ActionSheet elements

我需要帮助为操作中的按钮提供辅助功能标识符 sheet。我有 3 个

let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertController.Style.actionSheet)
actionsheet.addAction(UIAlertAction(title: "Add new", style: .default, handler: ....))
actionsheet.addAction(UIAlertAction(title: "Remove", style: .destructive, handler: ....))

这是代码,我想为每个“添加新”和“删除”操作设置辅助功能标识符。提前谢谢你

你可以像下面的代码一样通过让动作然后设置标识符来完成它

 let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertController.Style.actionSheet)
 let newAction = UIAlertAction(title: "Add new", style: .default, handler: {_ in })
 newAction.accessibilityIdentifier = "identifier"
 actionSheet.addAction(newAction)