views:

365

answers:

3

I've got a Core Data application that has an Event class, which has a start date and a finish date. It's trivial to bind these to a pair of NSDatePicker widgets, but I wanted to make it work with the NSRangeDateMode available in Leopard.

The NSDatePicker has a pair of methods that deal with timeInterval, but I don't seem to be able to bind to this.

Update: I've used a manual call to do the binding, and it half works:

[picker bind:@"timeInterval" 
    toObject:array 
 withKeyPath:@"selection.timeInterval" 
     options:options];

It sets the timeInterval in the NSDatePicker when the underlying object is changed, but does not set the underlying object when the NSDatePicker's timeInterval is changed.

+1  A: 

The interval support is only available when you're using the graphical version of the date picker. Even then, there's no native binding support for timeInterval.

Also depending on how you're intending to use this the UI to select ranges that extend past the current month is poor in my opinion.

Ashley Clark
Yeah. And it doesn't work if you have a Binding set up on Value (dateValue).
Matthew Schinckel
There seems to be partial support for binding to the timeInterval, just not in Interface Builder (see my update above).
Matthew Schinckel
+1  A: 

Sadly, no. The timeInterval property of the date picker is not even properly key-value observable. Basically, you're stuck either setting up an action method or using the delegate validation method to receive updates to its value. Also, you'll want to round it off to the nearest multiple of 86400.0 (i.e. the number of seconds in a day), since the date picker is consistently off by some fraction of a second in its reported timeInterval. Perhaps by the time Snow Leopard rolls around, this feature will be fully baked.

Boaz Stuller
This suggestion made me think about how to get it to work - I have subclassed NSDatePickerCell, and tried to make it fully KVO compliant for timeInterval, but this resulted in an infinite loop. I'll try the delegate validation method (which I had used first, as it turns out).
Matthew Schinckel
A: 

1169097 explains how to implement custom bindings.

yakovlev