Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monthly view doesn't show events until touch event. #23

Closed
Jeremy1026 opened this issue Oct 23, 2013 · 2 comments
Closed

Monthly view doesn't show events until touch event. #23

Jeremy1026 opened this issue Oct 23, 2013 · 2 comments

Comments

@Jeremy1026
Copy link

I am loading an CKCalendarView in my view controller, and the calendar presents and the dots are added to each day that there is event(s) for that date. Now, if there are events for the given day, the events table shows "No Events Today" until the current day is touched.

@MosheBerman
Copy link
Owner

I'm looking into this issue and issue #57. I'm having trouble reproducing. Can you please provide a code sample?

@MosheBerman
Copy link
Owner

So I looked into this and worked it out.

When you tap on a day in the calendar, it creates an NSDate object with a year, month, and day. The time values are all set to zero.

The NSDate created by the "today" button in the CKCalendarViewController and the NSDate create by the calendar view on instantiation is created by calling [NSDate date]. Those dates have hour, minute, and second values.

When trying to key into the data source dictionary, you're not going to match if you have time values specified. That's why tapping on a date shows events and the default date and the today button don't show events correctly.

There are two ways to fix this.

  1. Be stricter about setting dates. When setting an NSDate, we can use the current calendar to strip out anything but the year, month, and day values, like so:
    NSDateComponents *components = [self.calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:date];
    date = [self.calendar dateFromComponents:components];
  1. We can be looser about what dates we accept as "matches" in the data source. (That is, do less greedy matches in the calendar when we're checking for events.

Unless we need the precision of a stricter date in the calendar, we're better off, in my opinion, with the first option.

As it is now, the calendar does not manage events internally, and doesn't get more precise than the "day" unit. As such, there isn't much benefit to making that calculation of what dates fall into what ranges whenever there's a call to the data source. It seems more efficient to truncate the time part of the date once, when we set it.

I'm happy to say that commit cc7f098 implements the first of these two fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants