我有一个事件(称为“测试事件”),从 11 月 6 日凌晨 2 点开始,到 11 月 24 日上午 10 点结束。当我尝试通过指定一天的范围来查找事件时,我可以找到它所有天(11 月 6 日、11 月 7 日、...、11 月 23 日)11 月 24 日除外。
每次用户选择新的一天时,都会调用以下方法:
- (void)loadItemsFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate
{
NSLog(@"loadItemsFromDate");
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSLog(@"%@ to %@", [dateFormatter stringFromDate:fromDate], [dateFormatter stringFromDate:toDate]);
// Create the predicate from the event store's instance method
NSPredicate *predicate = [self.store predicateForEventsWithStartDate:fromDate
endDate:toDate
calendars:nil];
NSLog(@"predicateFormat: %@", [predicate predicateFormat]);
// Fetch all events that match the predicate
self.currentDayEvents = [self.store eventsMatchingPredicate:predicate];
NSLog(@"single day events:");
for(EKEvent *event in self.currentDayEvents)
{
NSLog(@"title: %@, start: %@, end: %@", event.title, [dateFormatter stringFromDate:event.startDate], [dateFormatter stringFromDate:event.endDate]);
}
NSLog(@"\n");
}
这是用户选择 11 月 6 日时的日志(可以找到“测试事件”):
loadItemsFromDate
11/6/12, 12:00 AM to 11/6/12, 11:59 PM
predicateFormat: EKEventPredicate start:11/6/12, 12:00 AM; end:11/6/12, 11:59 PM; cals:(null)
single day events:
title: Vote, start: 11/6/12, 12:00 AM, end: 11/6/12, 11:59 PM
title: Test Event, start: 11/6/12, 2:00 AM, end: 11/24/12, 10:00 AM
11 月 7 日到 22 日看起来都与此日志相似,这是 11 月 23 日的日志(可以找到“测试事件”):
loadItemsFromDate
11/23/12, 12:00 AM to 11/23/12, 11:59 PM
predicateFormat: EKEventPredicate start:11/23/12, 12:00 AM; end:11/23/12, 11:59 PM; cals:(null)
single day events:
title: Test Event, start: 11/6/12, 2:00 AM, end: 11/24/12, 10:00 AM
这是 11 月 24 日的日志(由于未返回“测试事件”,因此无法按预期工作):
loadItemsFromDate
11/24/12, 12:00 AM to 11/24/12, 11:59 PM
predicateFormat: EKEventPredicate start:11/24/12, 12:00 AM; end:11/24/12, 11:59 PM; cals:(null)
single day events:
为什么即使活动在当天上午 10 点结束,它也找不到 11 月 24 日的活动?我正在运行 iOS 6.0.1。