"UITabBarSwappableImageView", -6ren">
gpt4 book ai didi

ios - 葫芦 iOS : how to get value using query command

转载 作者:太空宇宙 更新时间:2023-11-03 17:23:31 26 4
gpt4 key购买 nike

我正在尝试使用查询命令获取每个类的值。下面是我得到的示例 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 获取值时则不行。

有人可以解释一下吗?

最佳答案

简短回答:'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

退后一步,我想我知道您要做什么 - 获取可见 View 的综合列表。

看看https://github.com/jmoody/briar/blob/master/lib/briar/irbrc.rb

示例输出在这里:https://gist.github.com/jmoody/8031917

不是在查询中调用“class”,而是遍历查询返回的结果并查找“class”键的值。

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

关于ios - 葫芦 iOS : how to get value using query command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22214292/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com