I am trying to reset the UIPickerView
on button click. After searching StackOverflow I found:
[picker reloadAllComponents];
[picker selectRow:0 inComponent:0 animated:YES];
I rewrote it in Ruby like this:
def reset_picker
@picker.reloadAllComponents
@picker.selectRow( 0, inComponent: 0, animated: true)
end
The above only resets the first component; how do I reset all three components? I know it has something to do the inComponent: 0
in the reset_picker
method.
Below are the UIPickerView
method calls:
def numberOfComponentsInPickerView(pickerView)
component_options.count
end
def pickerView(pickerView, numberOfRowsInComponent: component)
component_options[component].count
end
def pickerView(pickerView, titleForRow: row, forComponent: component)
component_options[component][row]
end
You are right - The inComponent: 0
relates to the index of the component.
With that in mind, to reset all three components you just need to:
def reset_picker
@picker.reloadAllComponents
@picker.selectRow( 0, inComponent: 0, animated: true)
@picker.selectRow( 0, inComponent: 1, animated: true)
@picker.selectRow( 0, inComponent: 2, animated: true)
end