PDA

View Full Version : Can I set a couple year to DatePicker?




mikezang
Jul 14, 2010, 07:40 AM
I am using DatePicker, and I want to know if I can set year to 2010, 2015 and so on, then the DatePicker can only be selected for year 2010 and 2015, is this possible?



robbieduncan
Jul 14, 2010, 07:51 AM
It might be possible with a custom (supplied by you) NSCalendar object that represents the dates you want. This seems very complex though. If you simply want to allow the user to pick from a set of years why not use a UIPickerView, specify the correct number of components and use the data source to only allow the values you want?

And before you ask, no I won't supply "sample code" for you to copy and paste and then claim as your own. The documentation should be more than enough to work this out.

mikezang
Jul 14, 2010, 07:57 AM
Now I just finished DatePicker, like you said, the next step is to make a PcikerView, I hope I can finish it by myself.

Thanks for your suggestion.

PhoneyDeveloper
Jul 14, 2010, 11:28 AM
Why don't you use the minimumDate, maximumDate properties to make this work?

robbieduncan
Jul 14, 2010, 11:34 AM
Why don't you use the minimumDate, maximumDate properties to make this work?

Can you use those to set a non-contiguous date range? Seems that the OP wants to allow the user to choose a year of 2010 or 2015 but not 2011,2012, 2013 or 2014.

PhoneyDeveloper
Jul 14, 2010, 03:12 PM
I doubt it can be used for discontinuous date ranges. Is that really what OP wants? Sounds very oddball that the date picker would go from Dec 2010 to Jan 2015. There's probably a better UI for that.

robbieduncan
Jul 14, 2010, 03:14 PM
I doubt it can be used for discontinuous date ranges. Is that really what OP wants? Sounds very oddball that the date picker would go from Dec 2010 to Jan 2015. There's probably a better UI for that.

I can think of uses for that sort of thing. Say choosing individual dates from past Olympics/major sports championships...