配列に書き込まれた管理オブジェクト コンテキストに対してフェッチ要求を実行します。フェッチ自体はうまく機能し、配列は正しく埋められます。ただし、(セル ベースの) テーブル ビューに配列の内容を表示しようとすると、何も表示されません。セットアップは次のとおりです。
- コンテンツ配列は、ファイルの
NSArrayControllers
所有者の結果配列 (私が理解している限り、NSManagedObject
オブジェクトで満たされています) にバインドされています。ここでは、エンティティ モードとクラス モードの両方を試しました。 - テーブル ビューのコンテンツは、オブジェクトを配置した配列コントローラーにバインドされます。
- テーブル列の値は、コントローラ キー: 配置されたオブジェクト、モデル キー パス: プロパティ名 (データ モデルで定義されている) を使用して配列コントローラにバインドされます。
NSManagedObject
クラス モードでバインディングのプロパティにアクセスするために、オブジェクトのサブクラスも作成しました。
上記のいずれも、テーブル ビューがフェッチ リクエストの結果で満たされていませんでした。それで、誰かがこれを正しくするのを手伝ってくれますか? ありがとう!
リクエストに応じて、fetch メソッドのコードを次に示します (他のすべては Interface Builder で行います)。
- (IBAction)fetch:(id)sender {
NSLog(@"Performing fetch.");
NSManagedObjectContext *moc = [self managedObjectContext];
// Connecting entity
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName:@"Operation"
inManagedObjectContext:moc];
//Creating fetch request
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
// Set predicate for fetch request
float maxDurationInMinutes = [durationFetchInput floatValue];
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"(durationInMinutes >= %f)", maxDurationInMinutes];
[request setPredicate:predicate];
//Set sort ordering for fetch request
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@"durationInMinutes" ascending:YES];
[request setSortDescriptors:@[sortDescriptor]];
NSError *error;
NSArray *array = [moc executeFetchRequest:request error:&error];
fetchReturnArray = [[NSArray alloc] initWithArray:array];
[objectsCountOutput setIntegerValue:[fetchReturnArray count]];
if (array == nil)
{
NSLog(@"Error fetching...");
}
NSLog(@"%@",fetchReturnArray);
}