David Bewick
David Bewick

Reputation: 43

CPDatePicker - open at dateValue not today's month

Can you programatically trigger the buttons on a CPDatePicker graphical calendar? I'm setting the date object fine, but the calendar initially displays the current month, with today's day in blue, rather than the dateValue month. Clicking the little circle button between the month arrow stepper buttons switches the display to the dateValue. I'm doing this in code not IB. I have trawled CP and NS documentation but am stuck!

Upvotes: 1

Views: 46

Answers (1)

Kris
Kris

Reputation: 41877

The implementation for CPDatePicker uses a Control _CPDatePickerCalendar for display purposes in the mode I think you're asking about. This control appears to set its view to display whatever date was selected:

- (void)setDateValue:(CPDate)aDateValue
{
    var dateValue = [aDateValue copy];
    [dateValue _dateWithTimeZone:[_datePicker timeZone]];

    [_monthView setMonthForDate:dateValue];
    [_headerView setMonthForDate:[_monthView monthDate]];

    [self setNeedsLayout];
    [self setNeedsDisplay:YES]; // <-- makes cappuccino redraw the calendar
}

This is called from the CPDatePicker when its' dateValue property is written to. So I would believe think that what you want to accomplish is default behaviour.

Perhaps the CPCalendar is not added as subView to a CPWindow when you set the date and therefor the view isn't updated at time of setting the value?

Upvotes: 0

Related Questions