问题描述
我想在表视图的section标题中显示一个格式化的日期。
I want to show a formatted date in the section header of a table view..
我使用下面的代码,但它抛出一个异常 ***由于未捕获异常NSInvalidArgumentException而终止应用程序,原因:'keypath dateSectionIdentifier在实体中找不到< NSSQLEntity费用id = 1>'
。
I used the following code.but its throwing an exception *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath dateSectionIdentifier not found in entity <NSSQLEntity Expense id=1>'
.
猜测在添加排序描述符时会出现异常。
guess the exception is coming when adding a sort descriptor.
NSMutableArray *sortDescriptors = [[NSMutableArray alloc] initWithCapacity:20];
NSSortDescriptor *mainSortDescriptor = [[NSSortDescriptor alloc] initWithKey:dateSectionIdentifier ascending:NO];
[sortDescriptors addObject:mainSortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
// Expense.h
//Expense.h
NSString *dateSectionIdentifier;
// Expense.m
//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是一个临时的属性。
The title of your question indicates that "dateSectionIdentifier" is a transient property.
您不能在排序描述符中使用transient属性)的核心数据提取请求,如果SQLite用作存储类型。这是一个记录的限制,只能使用持久属性。
You cannot use a transient property in a sort descriptor (or in a predicate) of a Core Data fetch request if SQLite is used as store type. That is a documented restriction, only persistent properties can be used.
请参阅。
这篇关于密钥< transientproperty>在实体中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!