Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
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.

Thanks
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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:

NSRangeDateMode

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

Available on Mac OS X v10.4 and later.
 

kpua

macrumors 6502
Jul 25, 2006
294
0
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:
get the newly selected date (when I have set a date) for use somewhere else
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:

Code:
- (IBAction)printDate:(id)sender {
NSLog(@"The selected date is: %@", [sender dateValue]);
}
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
You currently cannot use this control to select ranges of dates
Yes, I saw that, but since iCal has something like that I thought it would be possible in some (other) way.


kpua said:
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.
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.

Thanks
 

kpua

macrumors 6502
Jul 25, 2006
294
0
MrFusion said:
I didn't expect that calling dateValue would have a different outcome if it's used with an action, as in your example.

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.
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
kpua said:
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.