0

我只是想把我的头脑集中在核心数据上。我已经设法在 applicationDidFinishLaunching 中加载了一些数据,但现在我想做一些更复杂的事情。当我从视图控制器 B 回到视图控制器 A 时,我想将配方名称从 B 发送回 A,然后将其写入核心数据。我收到此错误:

CoreData:错误:无法在 NSManagedObject 类“Recipe”2013-11-01 19:10:07.886 RecipesWithCore[96409:70b] -[Recipe setRecipeName:] 上调用指定初始化程序:无法识别的选择器发送到实例 0x8c8cf40 2013-11-01 19 :10:07.890 RecipesWithCore [96409:70b] *由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[Recipe setRecipeName:]:无法识别的选择器发送到实例0x8c8cf40'

这是我的 unwindToRecipes:

-(IBAction) unwindToRecipes:(UIStoryboardSegue *)segue{
    DBKAddRecipeViewController *source = [segue sourceViewController];

    NSString *rn = source.recipe.recipeName;
    if (recipe != nil){
        //Add the recipe to coredata

        NSManagedObjectContext *context = [self managedObjectContext];
        NSManagedObject *newRecipe = [NSEntityDescription
                                   insertNewObjectForEntityForName:@"Recipe"
                                   inManagedObjectContext:context];

        [newRecipe setValue:rn forKey:@"recipeName"];

    }
}
4

1 回答 1

0

似乎insertNewObject返回一个Recipe类,而不是一个NSManagedObject. 检查你的Recipe类并确保你在它的@interface 以及@dynamic recipeName它的@implementation 中有正确的声明。还要检查您的托管对象模型并确保属性名称确实是recipeName.

于 2013-11-02T09:25:56.430 回答