0

I have a UIPickerView on an iOS app. Trying to use calabash-ios to scroll down on the UIPickerView to a specific value. It is a list of years.

I tried this to see if it will scroll at least:

    Then I scroll down on "myPickerAccessibilityLabel"

Didn't work

Is there a custom step for UIPickerView's?

haitham
  • 3,398
  • 6
  • 21
  • 35

2 Answers2

1

You should be able to use something like

Then I change the date on picker to "2016"

Based on the reply to another SO Calabash: Select a date from a UIDatePickerview

Community
  • 1
  • 1
Lasse
  • 1,153
  • 1
  • 10
  • 21
0

Lasse's answer is correct (I up-voted). But just to be clear, it will only work on UIDatePickers. I was just looking at the Calabash iOS sources and it looks like we have marked some of the picker methods private. The following was grabbed from the briar gem. It uses private UIKit selectors to manipulate the picker wheels. The caveat is that it might not work on non-circular (infinite) pickers.

You can use the code below to write a Step that scrolls a picker column to row with text.

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
jmoody
  • 2,480
  • 1
  • 16
  • 22
  • It is not clear from your preamble, if you are saying this code will only work if the user also includes the briar gem, and de-privatizes several undocumented parts of it, or what. – Don Simon Feb 24 '16 at 17:58
  • I recommend using the briar gem as inspiration. You can use the briar gem, but its future is uncertain. – jmoody Feb 25 '16 at 09:39
  • Which is great, or not, since the code, despite having a field named "column", doesn't actually work with multiple-column pickers. If only you documented any of the projects you worked on, someone might be able to use them for inspiration. Code that claims to do something, but doesn't do it, and doesn't have any explanation of how it was supposedly going to accomplish the task at hand is not particularly helpful. I seems that your primary purpose with all your projects is to try and create consulting business for your employer. – Don Simon Feb 29 '16 at 17:07