Я хочу отображать отформатированную дату в заголовке раздела табличного представления.
Я использовал следующий код, но он выдал исключение *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath dateSectionIdentifier not found in entity <NSSQLEntity Expense id=1>'
.
предполагаю, что возникает исключение при добавлении дескриптора сортировки.
NSMutableArray *sortDescriptors = [[NSMutableArray alloc] initWithCapacity:20];
NSSortDescriptor *mainSortDescriptor = [[NSSortDescriptor alloc] initWithKey:dateSectionIdentifier ascending:NO];
[sortDescriptors addObject:mainSortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
//Expense.h
NSString *dateSectionIdentifier;
//Expense.m
@dynamic dateSectionIdentifier
-(NSString *)dateSectionIdentifier{
[self willAccessValueForKey:@"dateSectionIdentifier"];
NSString *tempDate = [self primitiveDateSectionIdentifier];
[self didAccessValueForKey:@"dateSectionIdentifier"];
if(!tempDate){
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"d MMMM yyyy"];
tempDate = [dateFormatter stringFromDate:[self date]];
[self setPrimitiveDateSectionIdentifier:tempDate];
[dateFormatter release];
}
return tempDate;
}
dateSectionIdentifier
- person CodaFi   schedule 12.04.2013