2014-03-06 64 views
1

我試圖使用查詢命令獲取每個類的值。 下面是示例UI組件,我得到:葫蘆iOS:如何使用查詢命令獲取值

[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 /等價值。

請問有人可以擺脫一些光線嗎?

回答

6

簡短的回答:「階級」是不是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

,而不是在查詢調用「類」,遍歷由查詢返回的結果,並尋找「類」的價值鍵。

query('*').map { |result| result['class'] } 
+0

謝謝jmoody! :) – user3363340

相關問題