我无法为fetchedResultedController创建fetchRequest。
我有3个型号:
@interface Event : NSManagedObject
@property (nonatomic, retain) Entertainment *entertainment;
@property (nonatomic, retain) Place *place;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSString * objectId;
//boolValue
@property (nonatomic, retain) NSNumber * threeDimensional;
//others properties
.......
@end
@interface Entertainment : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * objectId;
@property (nonatomic, retain) NSSet *events;
@property (nonatomic, retain) NSString *classNaming;
//others properties
.......
@end
@interface Place : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * objectId;
@property (nonatomic, retain) NSSet *events;
//others properties
.......
@end
所以我需要在tableView
(每行1个地方)显示具体日期(11月1日)和具体事件entertainment
以及所有活动时间(示例事件可能有时间14:30) ,第二次19:10,所以我需要在单元格中显示所有这些时间以获取具体位置)
示例:
所以这并不困难
- (NSFetchedResultsController *)fetchedResultsControllerForEntertainmentsWithEventsFromEntertainment:(Entertainment *)entertainment
date:(NSDate *)date
{
if (!place && !date)
return nil;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([Event class])];
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"yyyy/MM/dd";
NSDate *startDate = [dateFormatter dateFromString:[dateFormatter stringFromDate:date]];
NSDateComponents *oneDay = [NSDateComponents new];
oneDay.day = 1;
NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:oneDay toDate:startDate options:0];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"date >= %@ AND date < %@ AND entertainment.classNaming == %@ AND entertainment.objectId == %@", startDate, endDate, entertainment.classNaming, entertainment.objectId];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"entertainment.name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
fetchRequest.sortDescriptors = @[sortDescriptor];
fetchRequest.fetchBatchSize = 20;
NSFetchedResultsController *fetchResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"place.name" cacheName:nil];
return fetchResultsController;
}
所以我得到了fetchedResultsController,其中每个部分都是带有行数组的Place,每个部分都是这个Place的Event。
但我有一个大问题:
每个Event
都可以3D显示(属性threeDimensional
)。因此,如果Place有3D和非3D事件,则必须对其进行划分,因此一个单元格将显示场所的3D事件,另一个场景将显示非3D事件。我做了但没有fetchedResultsCntroller。我需要在fetchRequest中使用什么谓词来做这样的事情: