Darkseal / DownPicker

A lightweight DropDownList / ComboBox for iOS, written in Objective-C
MIT License
202 stars 93 forks source link

Add "set default option" feature #14

Closed WedgeSparda closed 8 years ago

WedgeSparda commented 8 years ago

It would be great to add a property to set a default selected option from the dataArray. This way, picker would show a selected option since the beginning.

Darkseal commented 8 years ago

What about adding a setter to the text property? We can handle it just like the text contained in the textField, as it would mostly be a shortcut for that (as it already is now): we also already have all the checks in place (see #11 and #12) to handle wrong input data.

WedgeSparda commented 8 years ago

The idea would be something like this: [picker setSelectedOptionIndex:3];

Then, the text field text would match that option's string value.

This way, you could change picker's value programmatically too.

Darkseal commented 8 years ago

Aah ok: you want to set a default selected option index too. I'll do both things this evening.

WedgeSparda commented 8 years ago

Yes, the important thing here is to avoid that the default selected text doesn't exists in the data array.

Darkseal commented 8 years ago

Actually the option was already there, setDefaultValue was doing exactly that. Anyway, I added a setter for text and a selectedIndex property with getter and setter, both of them supporting empty (nil) values, so you can programmatically reset the DownPicker initial state ("clearing" the user selection) by setting text = nil or selectedIndex = nil.

I also setup some basic unit testing, now the CI build is passing aswell ^_^

Please let me know if everything is working as intended.