Kal 在同一事件中显示 2 个单元格

发布于 2024-10-28 08:53:15 字数 510 浏览 2 评论 0原文

我创建了一个 iPhone 应用程序,它在选项卡栏环境中使用 Kal 框架。

我使用 EVENTKIT 框架创建一个新事件,它向用户显示如下: 在此处输入图像描述

单击完成后.. 事件保存..

但是 当我查看时Kal 日历显示同一事件的 2 个条目: 在此处输入图像描述

如果 我关闭应用程序,然后再次打开它,它会正确显示一个单元格中的事件条目..

但我不明白为什么它在添加后立即显示同一事件两次..

任何人都可以帮忙吗?

编辑: 当我单击“今天”按钮时,它似乎重置/刷新数据并且工作正常。 我目前正在尝试弄清楚如何在每次添加事件时刷新/重置它。

任何帮助将不胜感激:)

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:
enter image description here

after you click done.. the event saves..

BUT when I view the Kal calendar it shows 2 entries for the same event:
enter image description here

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 works 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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人生戏 2024-11-04 08:53:15

如果您的代码基于 NativeCal 示例,则存在错误

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

,因为 [events removeAllObjects] 在函数顶部调用,然后在 dispatch_async 块,如果在第一次调用完成之前再次调用该函数,则事件列表可能包含重复事件。我通过将 dispatch_async 调用更改为 dispatch_sync 来修复此问题,以阻止对主线程的回调并清除该调用中的事件列表,生成以下代码:

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];
  });
});

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];
  });
});
笨死的猪 2024-11-04 08:53:15

我对您将事件添加到 Kal 日历的解决方案感到困惑。我正在阅读头文件和实现文件 KalDataSource.h 和 KalDataSource.m,似乎创建事件的所有代码都应该发生在那里。无论如何,你能告诉我你在将事件添加到你的 kal 日历中做了什么吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文