2013-04-12 6 views
11

で見つかりません私は、テーブルビューのセクションヘッダーのフォーマットされた日付を表示したい..キーパス<transientproperty>エンティティ

私はその例外をスロー*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath dateSectionIdentifier not found in entity <NSSQLEntity Expense id=1>' code.but以下を使用します。

ソート記述子を追加するときに例外が発生していると推測されます。

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; 

} 
+1

私たちに 'dateSectionIdentifier'の宣言と初期化を教えてください – CodaFi

答えて

28

あなたの質問のタイトル "dateSectionIdentifierは" 過渡財産であることを示しています。

SQLiteがストアタイプとして使用されている場合、コアデータフェッチ要求のソート記述子(または述語)に一時プロパティを使用することはできません。これは文書化された制限事項であり、永続プロパティのみを使用できます。

詳細については、「コアデータプログラミングガイド」 のPersistent Store Types and Behaviorsを参照してください。

+0

リンクが壊れています;( – Oriol

+0

@Oriol:通知ありがとう、私はリンクを更新しました。 –

0

サブクラスに「dateSectionIdentifier」を追加したが、.xcdatamodelIdファイルでは更新されなかったと思います。 .xcdatamodelIdファイルに「dateSectionIdentifier」が追加されているかどうかを確認するためにクロスチェックします。

関連する問題