3

I'm having following UI: enter image description here

Is it possible to disable only the last two components if the switch is used? If so, how can I do this?

Philipp Rosengart
  • 713
  • 1
  • 8
  • 20
  • You can look at this post http://stackoverflow.com/questions/1565743/uipickerview-disable-row-selection – Oleg Gordiichuk Mar 17 '17 at 09:08
  • I saw this post, but this is not what I want to do. It makes no sense to take a time if the whole day is switched on so I want to disable it. Scrolling to another time makes no sense for me – Philipp Rosengart Mar 17 '17 at 09:10

2 Answers2

1

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
    }
}
Rob
  • 2,649
  • 3
  • 27
  • 34
0

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.

Apurv
  • 17,116
  • 8
  • 51
  • 67