UITableViewCell 中的 XCUIElement 层次结构 [英] XCUIElement hierarchy within UITableViewCell
问题描述
我在 UI 测试中遇到了一个奇怪的行为.当我将自定义视图添加到 UITableViewCell 时,它的某些子视图无法访问.但是,在 Xcode 的 Debug View Hierarchy 中是可以的.
I encountered a strange behaviour in UI-tests. When I add a custom view into UITableViewCell, some of it's subviews are not accessible. However, it's OK in Xcode's Debug View Hierarchy.
是的,我知道 UIAccessibilityContainer 但这不是解决方案的原因:1.我的自定义视图中有常规的子视图(视图、标签、图像),而不是绘制的内容.2. 我不能为 containerView 禁用 isAccessibilityElement 并为 ImageView 启用它,因为我同时需要两者.
Yes, I know about UIAccessibilityContainer but it's not a solution cause of: 1. there are regular subviews in my custom view (views, labels, images), not a drawn content. 2. I can't disable isAccessibilityElement for containerView and enable it for ImageView cause of I need both in the same time.
因此,当我按原样将视图添加到 TableViewCell 时,我只能访问 UI 测试中的几个元素:
So, when I add my view to TableViewCell as-is, I can access only few elements from UI-tests:
Table, 0x604000196da0, traits: 35192962023424, {{5.0, 108.0}, {404.0, 586.0}}
Cell, 0x604000384b90, traits: 8589934592, {{5.0, 132.0}, {365.0, 329.0}}
StaticText, 0x6040003849f0, traits: 8589934656, {{9.0, 135.7}, {25.0, 12.7}}, identifier: 'myLabel', label: '123'
StaticText, 0x604000384780, traits: 8589934656, {{73.0, 154.3}, {293.0, 18.7}}, identifier: 'titleLabel', label: 'Title'
如果我为图像启用 isAccessibilityElement,我也可以看到它:
If I enable isAccessibilityElement for images, I can see it as well:
Table, 0x604000196da0, traits: 35192962023424, {{5.0, 108.0}, {404.0, 586.0}}
Cell, 0x604000384b90, traits: 8589934592, {{5.0, 132.0}, {365.0, 329.0}}
Image, 0x604000384ac0, traits: 8589934596, {{9.0, 235.7}, {357.0, 174.3}}, identifier: 'myImage'
StaticText, 0x6040003849f0, traits: 8589934656, {{9.0, 135.7}, {25.0, 12.7}}, identifier: 'myLabel', label: '123'
StaticText, 0x604000384780, traits: 8589934656, {{73.0, 154.3}, {293.0, 18.7}}, identifier: 'titleLabel', label: 'Title'
Image, 0x604000384370, traits: 8589934596, {{9.0, 156.3}, {56.0, 56.0}}, identifier: 'myIcon'
但是,在这两种情况下,Cell 内的层次结构都很简单,并且没有容器视图.
But, in both cases a hierarchy within Cell is plain and there are no container views.
推荐答案
解决方案是:使用 UICollectionView 而不是 UITableView.
这是一个正确的层次结构(isAccessibilityElement 对每个元素都有默认值).
Here is a correct hierarchy (isAccessibilityElement has default value for each element).
Other, 0x600000193590, traits: 8589934592, {{5.0, 132.0}, {365.0, 604.0}}
CollectionView, 0x6000001930b0, traits: 35192962023424, {{5.0, 132.0}, {365.0, 573.0}}
Cell, 0x600000192fe0, traits: 8589934592, {{5.0, 132.0}, {365.0, 329.0}}
Other, 0x600000192f10, traits: 8589934592, {{5.0, 132.0}, {365.0, 329.0}}
Other, 0x6040001900c0, traits: 8589934592, {{0.0, 129.7}, {375.0, 333.7}}, identifier: 'myView'
Other, 0x604000192e40, traits: 8589934592, {{0.0, 129.7}, {375.0, 333.9}}, identifier: 'contentView'
StaticText, 0x60400018f970, traits: 8589934656, {{4.0, 133.7}, {25.0, 12.7}}, identifier: 'myLabel', label: '123'
Image, 0x60400018fd80, traits: 8589934596, {{4.0, 154.3}, {56.0, 56.0}}, identifier: 'myIcon'
StaticText, 0x60400018f7d0, traits: 8589934656, {{68.0, 152.3}, {303.0, 18.7}}, identifier: 'titleLabel', label: 'Title'
Other, 0x60400018ee10, traits: 8589934592, {{4.0, 233.7}, {367.0, 179.2}}, identifier: 'containerView'
Image, 0x60400018eba0, traits: 8589934596, {{4.0, 233.7}, {367.0, 179.2}}, identifier: 'myImage'
这篇关于UITableViewCell 中的 XCUIElement 层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!