2016-09-23 2 views
0

3つのコントローラを持つコンテナビューコントローラを作成しました。これは2番目のビューコントローラ(VC)です。私が最初にVC第二と第二VCの代わりに、最初のVCを移動したときに、このエラーがあります:'NSInvalidArgumentException'を解決する方法、 '+ entityForName:nilは法的なNSManagedObjectContextではありません

「NSInvalidArgumentException」、理由:「+ entityForName:nilのエンティティ名を検索法的NSManagedObjectContextパラメータではありません[プログラム] 「

NSEntityDescription *entitydesc = [NSEntityDescription entityForName:@"Programs" inManagedObjectContext:context]; 
    NSFetchRequest *request = [[NSFetchRequest alloc]init]; 
    request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"programId" ascending:YES]]; 


request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"startTime" ascending:NO], [NSSortDescriptor sortDescriptorWithKey:@"day" ascending:YES]]; 

私のビューコントローラコード

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { 
controller1 = [[Home alloc]initWithNibName:@"Home" bundle:nil]; 
} 
else 
{ 
    controller1 = [[Home alloc]initWithNibName:@"Home_iPad" bundle:nil]; 
} 
controller1.title = @"Home"; 
controller1.delegate2 = self; 

controller2 = [storyboard instantiateViewControllerWithIdentifier:@"Activity"]; 
controller2.title = @"Activity"; 
controller2.delegate = self; 


if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { 
controller3 = [[League alloc] initWithNibName:@"League" bundle:nil]; 
} 
else 
{ 
    controller3 = [[League alloc] initWithNibName:@"League_iPad" bundle:nil]; 
} 
controller3.title = @"League"; 



// controller4 = [[Messages alloc] initWithNibName:@"Messages" bundle:nil]; 
// controller4.title = @"Message"; 



NSArray *controllerArray = @[ controller2,controller1, controller3]; 
+0

あなたのエンティティ名が正確に "プログラム"かどうかを確認できますか? (NSManagedObjectContext * - – Arun

+0

はい、私のエンティティ名が私のメインビューコントローラやビューコントローラoのプログラム – user6584316

答えて

0

はあなたが私(.M)ファイルのコードを表示することができます。だから私はあなたを助けることができます。あなたの "文脈"がゼロであるためです。

+0

.mファイルでは、ちょうどこのコードチェックを使用しますが、「managedObjectContext」かどうか、私は を知っているようになっていることに – user6584316

+0

が埋め込まれています)managedObjectContext { NSManagedObjectContext * context = nil; id delegate = [[UIApplication sharedApplication] delegate]; if([delegate performSelector:@セレクタ(managedObjectContext)]){ context = [delegate managedObjectContext]; } return context; } –

+0

いいえ私はエラーが宣言されていませんmanageObjectcontext – user6584316

関連する問題