0
此代碼在iOS 6上正常工作,但不會在iOS 5上返回任何結果。使用類別方法將日期設置爲今天。任何人都能發現任何奇怪的東西嗎謝謝!奇怪的iOS 5 FetchedResultsController謂詞問題
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;
}
sectionNameKeyPath在哪裏?另外,你確定你傳遞的NSManagedObjectContext是一個有效的嗎? – sixthcent
sectionNameKeyPath屬於我根據日期區分事物的類別。如果我在iOS 5中評論謂詞,我會返回一些數據。謝謝。 –
您能否請您發佈[NSDate today]實施以節省我們的時間來編寫它? –