简体   繁体   中英

Swift UIPickerView disable component

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?

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.

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
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM