我想在 TableView 的节标题中显示格式化日期..
我使用了下面的代码。但是它抛出了一个异常 *** 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];
//费用.h
NSString *dateSectionIdentifier;
//费用.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”是一个 transient 属性。
如果将 SQLite 用作存储类型,则不能在核心数据提取请求的排序描述符(或谓词)中使用 transient 属性。这是记录在案的限制,只能使用持久属性。
参见 Persistent Store Types and Behaviors在《核心数据编程指南》中 获取更多信息。
关于ios - 在实体中找不到键路径 <transientproperty>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15972040/