Ios +;entityForName:nil不是搜索实体名称的合法NSManagedObjectContext参数';人';

Ios +;entityForName:nil不是搜索实体名称的合法NSManagedObjectContext参数';人';,ios,core-data,Ios,Core Data,我用objC语言将核心数据用于表视图。它可以成功启动,但单击AddView中的“完成”按钮后,出现错误: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“+entityForName:nil不是搜索实体名称“Person”的合法NSManagedObjectContext参数”* 如果context为nil,请检查它为什么为nil?检查应用程序代理的代码并将断点放在创建上下文的位置,检查是否成功创建了持久性存储协调器 -(void)action_a

我用objC语言将核心数据用于表视图。它可以成功启动,但单击AddView中的“完成”按钮后,出现错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“+entityForName:nil不是搜索实体名称“Person”的合法NSManagedObjectContext参数”*


如果
context
为nil,请检查它为什么为
nil
?检查应用程序代理的代码并将断点放在创建上下文的位置,检查是否成功创建了持久性存储协调器
-(void)action_addInformation:(id)sender
    {
        NSLog(@"add person information");
        @try {

             AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
            context = [appDelegate manageObjectContext];

            NSEntityDescription *entityDescription=[NSEntityDescription entityForName:@"Person" inManagedObjectContext:context];
            NSManagedObject *newPerson=[[NSManagedObject alloc]initWithEntity:entityDescription insertIntoManagedObjectContext:context];
            [newPerson setValue:firstNameTxtField.text forKey:@"firstname"];
            [newPerson setValue:lastNameTxtField.text forKey:@"lastname"];

            NSError *error;
            [context save:&error];
            NSLog(@"Information added successfully");

        } @catch (NSException *exception) {
            NSLog(@"%@",exception);
        } @finally {

        }
        }