【问题标题】:Retrieve EKEvent with specific title in EKEventStore在 EKEventStore 中检索具有特定标题的 EKEvent
【发布时间】:2012-12-09 23:20:50
【问题描述】:

您好,我在 iCloud 上的特定日历中保存了一些 EKEvent,我想检索其中一些具有特定标题的 EKEvent,这可能吗?我看到有这个方法:

eventsMatchingPredicate

但只有一个谓词:

predicateForEventsWithStartDate:endDate:calendars:

我想找到 EKEvent 作为标题,有什么想法吗?

【问题讨论】:

    标签: iphone ios ekevent ekeventstore


    【解决方案1】:

    我建议您存储事件的 ID,然后使用 EKEventStore 方法 - (EKEvent *)eventWithIdentifier:(NSString *)identifier 获取它

    编辑:啊哈,现在我明白你的问题了。不幸的是,您可以与 EKEventStore 一起使用的唯一谓词是 - (NSPredicate *)predicateForEventsWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate calendars:(NSArray *)calendars

    因此,您必须提供开始日期和结束日期才能获取这些日期之间的事件。获取事件后,您可以使用 NSArray - filteredArrayUsingPredicate: 过滤事件,这样您就可以给它一个带有事件标题的谓词。

    【讨论】:

    • 太多了,找标题很简单,因为标题一样...
    • 好的,谢谢,我如何在谓词中设置标题?可以举个例子吗?
    • [NSPredicate predicateWithFormat:@"title == %@", titleYourLookingFor];在这里查看更多关于谓词developer.apple.com/library/mac/documentation/Cocoa/Conceptual/…
    • @Piero 将近 5 年了,现在仍然如此。即使NSCompoundPredicate 带有由predicateForEventsWithStartDate:endDate:calendars: 创建的谓词以及一些自定义的与andPredicateWithSubpredicates 组合在一起的谓词,也会导致谓词无效的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多