Swift UIPickerView disable component

不想你离开。 提交于 2020-01-04 16:56:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!