alerts-and-pickers icon indicating copy to clipboard operation
alerts-and-pickers copied to clipboard

How can I set multiple index in initialSelection

Open oniikal3 opened this issue 7 years ago • 2 comments
trafficstars

@dillidon As question. I need to set multiple initial selection in picker view. I have used it with 2 pickers so I have 2 values but I can only set selection for 1 column.

How can I set multiple selection. Is it possible?

oniikal3 avatar Mar 23 '18 11:03 oniikal3

@oniikal3 Every time you change the picker Action return index (column: Int, row: Int), so you can easily get necessary value using switch:

switch index.column:
case 1:
//...
case 2:
//...

dillidon avatar Mar 28 '18 09:03 dillidon

I have achieved this behaviour by editing the class PickerViewViewController here is my code

this is my implementation of the pickerView Screenshot 2019-12-27 at 1 44 49 PM

    let pickerViewSelectedValue: [PickerViewViewController.Index] = [(column: 0, row: month-1), (column: 1, row: yearIndex)]
    alert.addPickerView(values: pickerViewValues, initialSelection: pickerViewSelectedValue) { vc, picker, index, values in
        self.month = picker.selectedRow(inComponent: 0)+1
        self.year = Int(years[picker.selectedRow(inComponent: 1)])!
    }

this is the change i have made in PickerViewViewController

blue lines indicates the changes.

Screenshot 2019-12-27 at 1 43 18 PM Screenshot 2019-12-27 at 1 49 13 PM

sahibhussain avatar Dec 27 '19 08:12 sahibhussain