0
我正嘗試重置按鈕單擊上的UIPickerView
。搜索的StackOverflow後,我發現:如何將Objective C重寫爲RubyMotion
[picker reloadAllComponents];
[picker selectRow:0 inComponent:0 animated:YES];
我重寫它在紅寶石這樣的:
def reset_picker
@picker.reloadAllComponents
@picker.selectRow(0, inComponent: 0, animated: true)
end
上面僅重置第一分量;我如何重置所有三個組件?我知道在reset_picker
方法中有些事情要做inComponent:0
。
下面是UIPickerView
方法調用:
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
感謝您的幫助,該訣竅! – Hyetigran 2014-12-19 00:46:38
沒問題,很高興我能幫到你。次要的事情,但你不應該需要對'reloadAllComponents'的初始調用,我只是保持它適合你的代碼。 – InsertWittyName 2014-12-19 00:48:06
你說得對,沒有'reloadAllComponents',它工作正常。我可以把它放在'self.numberOfComponentsInPickerView.times do | x |'塊嗎? – Hyetigran 2014-12-19 17:00:35