Discussion in 'Mac Programming' started by MrFusion, Aug 2, 2006.

  1. macrumors 6502a

    I am trying to understand nsdatepicker, but the object is quite strange. Strange as in lack of methods. I have set the thing to graphical mode and I can set the date (it gets a blue color) and I can select another date (grey color). But what I can't do, is get the newly selected date (when I have set a date) for use somewhere else or select e.g. an entire week, let alone get all the dates back from the nsdatepicker object.

    I am looking for similar behaviour as in iCal.

  2. Moderator


    Staff Member

    It's very likely that iCal does not use this control. Almost the entire iCal app UI uses custom controls that are specific to iCal (use FScript Anywhere to check).

    You currently cannot use this control to select ranges of dates. From the documentation, which I'm sure you read posting right:


    Allow selection of a range of dates. (Not currently implemented.)

    Available on Mac OS X v10.4 and later.
  3. macrumors 6502

    What Robbie says about the date range mode is correct. It's not currently implemented, but Apple doesn't usually leave documented API in a non-working state for very long, so I would bet we see that feature in Leopard.

    As for your statement:
    I think you're just not looking hard enough. NSDatePicker is a subclass of NSControl, which means you can set an action on it, which is fired when the date is changed. You can access the date by sending the -dateValue method to it. So, the following method could be hooked up to the date picker's action to print the date to the console:

    - (IBAction)printDate:(id)sender {
    NSLog(@"The selected date is: %@", [sender dateValue]);
  4. macrumors 6502a

    Yes, I saw that, but since iCal has something like that I thought it would be possible in some (other) way.

    I am working on a second program now, so still relatively new to cocoa. I didn't expect that calling dateValue would have a different outcome if it's used with an action, as in your example.

  5. macrumors 6502

    I'm not sure what you mean by this. Perhaps I wasn't very clear. -dateValue doesn't have a different outcome in the context of an action. Whether or not you call it in the action, it always returns the current date displayed by the date picker. I was just pointing out that because the date picker is a control, you can hook up an action method to it so you can perform whatever actions you want whenever the date is changed.
  6. macrumors 6502a

    I did the following (which will show you I am new to cocoa). I set the date programmatically to the current date. I have a button that will read the date when pushed. I push the button and get the current date back. I change the date and push again. The current date is still returned.

    With your code it returns the selected date.

    So I didn't expect the same function to have a different outcome when used in a different way, or else I must have done something else wrong. Anyway, it doesn't matter anymore, since it works now.

Share This Page