ios – 无法设置UISegmentedControl段的accessibilityIdentifier

ios – 无法设置UISegmentedControl段的accessibilityIdentifier,第1张

概述我发现,即使我可以设置UISegmentedControl的段的accessibilityLabel(参见: How do I set the accesibility label for a particular segment of a UISegmentedControl?),我也无法设置accessibilityIdentifier,这对我的项目同样重要.出于自动化目的,我需要针对一个段而 我发现,即使我可以设置UISegmentedControl的段的accessibilityLabel(参见: How do I set the accesibility label for a particular segment of a UISegmentedControl?),我也无法设置accessibilityIDentifIEr,这对我的项目同样重要.出于自动化目的,我需要针对一个段而不管其文本和accessibilityLabel.

例如,代码:

Nsstring *name = [Nsstring stringWithFormat:@"Item %li",(long)IDx];segment.accessibilityIDentifIEr = name;NSLog(@"ID: %@",segment.accessibilityIDentifIEr);

结果是:

ID: (null)

没有异常被抛出.

有没有人深入了解为什么要实现accessibilityLabel,而不是accessibilityIDentifIEr?

解决方法 我通过为XCUIElement编写Swift扩展来解决这个问题,该扩展添加了一个新方法tap(at:UInt).此方法获取元素的按钮查询,并根据其x位置对结果进行排序.这允许我们指定我们想要点击的UISegmentedControl的哪个段而不是依赖于按钮文本.
extension XCUIElement {    func tap(at index: UInt) {        guard buttons.count > 0 else { return }        var segments = (0..<buttons.count).map { buttons.element(boundBy: ) }        segments.sort { .0.frame.origin.x < .1.frame.origin.x }        segments[Int(index)].tap()    }}
总结

以上是内存溢出为你收集整理的ios – 无法设置UISegmentedControl段的accessibilityIdentifier全部内容,希望文章能够帮你解决ios – 无法设置UISegmentedControl段的accessibilityIdentifier所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1104648.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存