kmcgill88 / McPicker-iOS

McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.
MIT License
213 stars 43 forks source link

Way to init with Selected Index? #14

Closed fabriciomasiero closed 7 years ago

fabriciomasiero commented 7 years ago

Hi,

There is a way to init the McPicker with custom selection index? Like, open Picker in position 10 of Array data

Thanks

kmcgill88 commented 7 years ago

Hi @fabriciomasiero, No there currently isn't a way to do that but it seems like a very valid use case. I like it!

Could probably accomplish this pretty easily by adding something like

    public var pickerSelectRowsForComponents: [Int:[Int:Bool]]? {
        didSet {
            for component in pickerSelectRowsForComponents!.keys {
                if let row = pickerSelectRowsForComponents![component]?.keys.first, let isAnimated = pickerSelectRowsForComponents![component]?.values.first {
                    picker.selectRow(row, inComponent: component, animated: isAnimated)
                }
            }
        }
    }

I'll make a branch and get it going!

kmcgill88 commented 7 years ago

@fabriciomasiero check out 0.4.0.

I've added

mcPicker.pickerSelectRowsForComponents = [
    0: [3: true],
    1: [2: true] // [Component: [Row: isAnimated]
]

For this use case.