dillidon / alerts-and-pickers

Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...
MIT License
5.66k stars 703 forks source link

How can I set multiple index in initialSelection #32

Open oniikal3 opened 6 years ago

oniikal3 commented 6 years ago

@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?

dillidon commented 6 years ago

@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:
//...
sahibhussain commented 4 years ago

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