1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Can I set a couple year to DatePicker?

Discussion in 'iPhone/iPad Programming' started by mikezang, Jul 14, 2010.

  1. macrumors 6502a

    #1
    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?
     
  2. Moderator

    robbieduncan

    Staff Member

    #2
    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.
     
  3. macrumors 6502a

    #3
    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.
     
  4. macrumors 68030

    PhoneyDeveloper

    #4
    Why don't you use the minimumDate, maximumDate properties to make this work?
     
  5. Moderator

    robbieduncan

    Staff Member

    #5
    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.
     
  6. macrumors 68030

    PhoneyDeveloper

    #6
    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.
     
  7. Moderator

    robbieduncan

    Staff Member

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

Share This Page