1

最新のXCode(4.5.1)とiOSシミュレーター5.1を実行しています。ここに問題があります。1つのコアデータモデルに2つのエンティティがあり、それらを表す2つのテーブルビューコントローラーがあります。2つのNSFetchedResultsControllers(tableviewcontrollerごとに1つ)を設定したいと思います。どちらも同じコンテキストで動作しますが、異なるエンティティで動作します。最初のものを作成するときは、すべて問題ありませんが、2番目のものを作成すると、initWithFetchRequest:メソッドでEXC_BAD_ACCESSが強制されます。使用するコードを提供することはできますが、ここでは必要ないと思います。基本的に、それは可能であり、そうでない場合は、私の問題に対するより良い解決策を見たいと思います。編集:コード:

showController.context = managedObjectContext;

self.showcaseController = [[UINavigationController alloc]initWithRootViewController:showController];
self.showcaseController.tabBarItem.title = @"Витрина";

categoryController = [[UMCategoriesController alloc] initWithNibName:@"UMCategoriesController" bundle:nil];
categoryController.context = managedObjectContext;

self.categoriesController = [[UINavigationController alloc]initWithRootViewController:categoryController];

したがって、基本的に、2つのUINavigationControllerで満たされたUITabBarControllerがあり、それぞれがUITableViewを含むUIViewControllerで始まります。AppDelegateで作成したNSManagedObjectContextを設定しました。これはUMShowcaseController.mNSFetchedResultsControllerのセッターです。ここでのみNSFetchedResultsControllerを使用すると、これは完全に機能します。

-(NSFetchedResultsController *) frc
{
if (_frc != nil)
{
    return _frc;
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Goods" inManagedObjectContext:context]];
_frc = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
_frc.delegate = self;
NSError __autoreleasing *error = nil;

if (![_frc performFetch:&error]) {
}
return _frc;
}

しかし、NSFetchedResultsControllerを2番目のUIViewControllerであるUMCategoriesViewに追加すると、クラッシュします。

if (_frc != nil)
{
    return _frc;
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Categories" inManagedObjectContext:context]];
_frc = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:nil cacheName:nil]; //here it fails
_frc.delegate = self;
NSError __autoreleasing *error = nil;

if (![_frc performFetch:&error]) {
}
return _frc;
4

1 に答える 1

0

くそー私は。ここで欠落しているのは、2番目のNSFetchedResultsControllerのソート記述子だけです。ドキュメントを読み直した後、すべてが正常に機能します。

ドキュメントを読み、ソート記述子を設定することを忘れないでください。

マーティン、コメントありがとうございます。ドキュメントを読み直させたのはあなたです。

于 2012-10-11T11:35:49.570 に答える