0

此代码在 iOS 6 上运行良好,但在 iOS 5 上不返回任何结果。日期使用类别方法设置为今天。任何人都可以发现任何奇怪的东西吗?谢谢!

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"KSJob"];

NSLog(@"today: %@", [NSDate today]);

// We only want to show upcoming jobs.
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"scheduledOn > %@", [NSDate today]]];

fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"scheduledOn" ascending:YES]];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                                                managedObjectContext:[(id)[[UIApplication sharedApplication] delegate]managedObjectContext]                                                 sectionNameKeyPath:@"dateToStringForSectionTitles"
                                                                           cacheName:@"UpcomingJobs"];
self.fetchedResultsController.delegate = self;

NSDate 类别方法:

+ (NSDate*) today
{
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *components = [cal components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[[NSDate alloc] init]];
    components.timeZone = [NSTimeZone localTimeZone];
    components.hour = 0;
    components.minute = 0;

    NSDate *today = [cal dateByAddingComponents:components toDate:[[NSDate alloc] init] options:0];    
    return today;
}
4

1 回答 1

0

好的,我想我找到了。由于某种原因,它似乎没有为 iOS 5 上的这些日期字段插入任何内容。但这解释了很多。

于 2013-04-03T18:47:07.570 回答