Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way using like 'didselect'?? #30

Closed
dev-yong opened this issue Feb 19, 2018 · 6 comments
Closed

Is there any way using like 'didselect'?? #30

dev-yong opened this issue Feb 19, 2018 · 6 comments

Comments

@dev-yong
Copy link

dev-yong commented Feb 19, 2018

#I have two related picker view
first picker : [ [Alphabet, Numbers] ]
second picker : [ [a,b,c, ...] or [1,2,3, ...] ]
if I select 'Alphabet' at first picker, second picker show [a,b,c, ...]
and if select 'Numbers', show [1,2,3, ...]

@kmcgill88
Copy link
Owner

kmcgill88 commented Feb 19, 2018

Hi @LeeGwangYong,

Were you trying to do this with 1 instance of McPicker? My first instinct says show McPicker with [ [Alphabet, Numbers] ], when the user makes a selection and McPicker closes, use the selection to show another instance of McPicker with [ [a,b,c, ...] or [1,2,3, ...] ] then once the user makes a selection you will have your final selections.

Adding a delegate to just listen for didSelect isn't bad ideal though! We could add a delegate callback here. I can see that use case being very helpful for those who want to know which value is selected before McPicker is closed with a selection.

@dev-yong
Copy link
Author

Yes! I want to use just 1 instance of McPicker. Thank you for your quick response.
And I will try to follow your advice.
Thank you 👍

@kmcgill88
Copy link
Owner

You could also try to subclass McPicker and override the delegate methods. Not sure that'll work but worth a shot. I'd like to keep McPicker simple and easy to use so I sorta shy away from adding things on the limb.

@dev-yong
Copy link
Author

I added some code at didselect method

public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        self.pickerSelection[component] = pickerData[component][row]
        (... update pickerData[1]...)
		picker.reloadComponent(1)
        picker.selectRow(0, inComponent: 1, animated: true)
        pickerSelection[1] = pickerData[1][0]
    }

it's really cool library

@kmcgill88
Copy link
Owner

Thanks @LeeGwangYong! This is a similar request @AlaeddineOuerteni pointed out wanting some control over the delegate too. I'm open to the idea, just curious how to best implement it. My first thought is to have McPicker have its own delegate method(s). Like McPickerViewDelegate, which would enforce proper use of data: [[String]] and pickerSelection: [Int:String] without actually exposing either publicly. I'm afraid it's opened it could be easily misused.

@kmcgill88
Copy link
Owner

Hello @LeeGwangYong, I have not cut a release yet but you might be interested in #32. It adds a SelectionChangedHandler. See the updated REAME in master branch for an example. I will cut a 1.0.0 release very soon! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants