如何解决' NSInvalidArgumentException',原因:' + entityForName:nil不是合法的NSManagedObjectContext

时间:2016-09-23 06:52:29

标签: ios objective-c

我创建了一个容器视图控制器,其中包含3个控制器,这是第二个视图控制器(VC)。当我在第一个VC中移动第一个VC代替第二个和第二个VC时出现此错误:

  

' 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];

1 个答案:

答案 0 :(得分:0)

你能告诉我(.m)文件代码吗?所以我可以帮助你。因为你的“背景”是零。