葫芦iOS:如何使用查询命令获取价值

我试图通过查询命令来获取每个类的值。 下面是我得到的示例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来完成这项工作,但是当我尝试从class / id / etc中获取值时,我不能使用它。

有人可以摆脱一些光?

简短的回答:“类”不是UIView实例上的select器

很长的回答:

 # 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'] }