我正在尝试使用query命令获取每个类的值。 下面是我得到的示例UI组件:
[0] {
"class" => "UITabBarSwappableImageView",
"id" => "imageView-34",
"rect" => {
"center_x" => 288,
"y" => 522,
"width" => 48,
"x" => 264,
"center_y" => 538,
"height" => 32
},
"frame" => {
"y" => 2,
"width" => 48,
"x" => 6,
"height" => 32
},
"label" => nil,
"description" => "<UITabBarSwappableImageVie....>"
在Android上,我可以使用它来列出类组件的所有值:
query("*", :class)
但是,我似乎无法在iOS上使用相同的命令。 我得到了这个结果:
irb(main):135:0> query "*", :class
[
[ 0] nil,
[ 1] nil,
[ 2] nil,
[ 3] nil
]
我知道使用标签,我可以使用:accessibilityLabel来完成这项工作,但是当我尝试从类/ id / etc中获取值时却不能。
有人可以解释一下吗?
答案 0 :(得分:6)
简短回答:'class'不是UIView实例上的选择器
答案很长:
# query( < look for some views >, < selector on the views found > )
# look for buttons marked 'big button' and call 'isSelected' selector on them
query("button marked:'big button'", :isSelected")
# look for labels marked 'title' and call 'text' selector on them
query("label marked:'title'", :text)
# look for all views and call 'class' selector on them
# whoops! 'class' is not a selector on UIView instances
query "*", :class
退后一步,我想我知道你要做什么 - 获得一个可见的全面视图列表。
查看https://github.com/jmoody/briar/blob/master/lib/briar/irbrc.rb
示例输出在此处:https://gist.github.com/jmoody/8031917
不是在查询中调用“class”,而是迭代查询返回的结果并查找“class”键的值。
query('*').map { |result| result['class'] }