问题
I'm having following UI:
Is it possible to disable only the last two components if the switch is used? If so, how can I do this?
回答1:
You can not disable the components. However you can reload picker using reloadAllComponents
method and you should reload only required components. Do not load time components.
回答2:
You can not disable the components. However you can try these solutions.
First solution:
var selectedRow3 = 3
var selectedRow4 = 3
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch component {
case 3:
myPicker.selectRow(selectedRow3, inComponent: component, animated: true)
case 4:
myPicker.selectRow(selectedRow4, inComponent: component, animated: true)
default:
break
}
}
Second solution:
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
switch component {
case 3:
return 1
case 4:
return 1
default:
return 10
}
}
回答3:
Yes, you can. But not using the native UIPickerView
. I have wrote a picker view named DLPickerView. This picker view was implemented based on UIScrollView
. You should check it.
来源:https://stackoverflow.com/questions/42853186/swift-uipickerview-disable-component