开发者

Kal showing 2 cells for the same event

I have created an iphone application which utilises the Kal framework within a tab bar environment.

I create a new event using the EVENTKIT framework and it shows up to the user like this:

Kal showing 2 cells for the same event

after you click done.. the event saves..

BUT when I view the Kal calendar it shows 2 entries for the same event:

Kal showing 2 cells for the same event

IF I close the application, then open it again, it correctly shows the event entry in one cell..

but I don't understand why it shows the same event twice immediately after I add it..

Can anyone help?

Edit: When I click the "Today" button it seems to reset/refresh the data and it work开发者_如何学Gos correctly.. I am currently trying to figure out how I could get it to refresh/reset every time an event is added..

Any help will be appreciated :)


If your code is based on the NativeCal example, there is a bug in

- (void)presentingDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate delegate:(id<KalDataSourceCallbacks>)delegate

because [events removeAllObjects] is called at the top of the function, and then is repopulated later in the dispatch_async block, the events list can contain duplicate events if the function is called again before the first call completes. I fixed this by changing the dispatch_async call to dispatch_sync to block on the call back to the main thread and to clear the events list in that call, producing the following code:

dispatch_async(eventStoreQueue, ^{
  NSDate *fetchProfilerStart = [NSDate date];
  NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:fromDate endDate:toDate calendars:nil];
  NSArray *matchedEvents = [eventStore eventsMatchingPredicate:predicate];
  dispatch_sync(dispatch_get_main_queue(), ^{
    NSLog(@"Fetched %d events in %f seconds", [matchedEvents count], -1.f * [fetchProfilerStart timeIntervalSinceNow]);
    [events removeAllObjects];
    [events addObjectsFromArray:matchedEvents];
    [delegate loadedDataSource:self];
  });
});


I am puzzled on your solution to adding events into the Kal calendar. I was reading the header file and implementation file KalDataSource.h and KalDataSource.m and it seems that all the code to create an event should occur there. Is their anyway you could tell me what you did in adding events into your kal calendar?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜