首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >calabash-ios UIPickerView滚动到特定值

calabash-ios UIPickerView滚动到特定值
EN

Stack Overflow用户
提问于 2015-06-03 19:42:29
回答 2查看 944关注 0票数 0

我在一个UIPickerView应用程序上有一个iOS。尝试使用calabash在UIPickerView上向下滚动到一个特定的值。这是一份年表。

我试过这样做,看看它是否会滚动:

代码语言:javascript
复制
    Then I scroll down on "myPickerAccessibilityLabel"

不起作用

UIPickerView有自定义步骤吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-04 12:54:06

拉塞的回答是正确的(我投了赞成票)。但是要明确的是,它只适用于UIDatePickers。我刚刚查看了Calabash的iOS源代码,看起来我们已经标记了一些私有的选择器方法。下面的是从荆棘宝石抓走的。它使用私有的UIKit选择器来操作选择器车轮。但要注意的是,它可能不适用于非循环(无限)采摘器。

您可以使用下面的代码编写一个步骤,将选择器列滚动到一行文本。

代码语言:javascript
复制
def picker_current_index_for_column (column)
  arr = query('pickerTableView', :selectionBarRow)
  arr[column]
end
# methods common to generic and date pickers
def picker_current_index_for_column_is(column, val)
  picker_current_index_for_column(column) == val
end

def previous_index_for_column (column)
  picker_current_index_for_column(column) - 1
end

def picker_next_index_for_column (column)
  picker_current_index_for_column(column) + 1
end

def picker_scroll_down_on_column(column)
  new_row = previous_index_for_column column
  query("pickerTableView index:'#{column}'", [{:selectRow => new_row},
                                              {:animated => 1},
                                              {:notify => 1}])
end

def picker_scroll_up_on_column(column)
  new_row = picker_next_index_for_column column
  query("pickerTableView index:'#{column}'", [{:selectRow => new_row},
                                              {:animated => 1},
                                              {:notify => 1}])
end
def visible_titles (column)
  query("pickerTableView index:#{column} child pickerTableViewWrapperCell", :wrappedView, :text).reverse
end

# May only work on circular pickers - does _not_ work on non-circular
# pickers because the visible titles do _not_ follow the selected index
def selected_title_for_column (column)
  selected_idx = picker_current_index_for_column column
  titles = visible_titles column
  titles[selected_idx]
end

def scroll_picker(dir, column)
  if dir.eql? 'down'
    picker_scroll_down_on_column column
  else
    picker_scroll_up_on_column column
  end
  sleep 0.4
end
票数 0
EN

Stack Overflow用户

发布于 2015-06-03 20:55:12

你应该可以使用

然后我将“挑选者”的日期改为"2016“

基于对另一个所以Calabash: Select a date from a UIDatePickerview的答复

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30629225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档