0

帮助!!!我有一个一对多的关系。

为什么 [self.menu addSubMenuObject:newSubMenu] 不起作用?

ManagerCoreData * managerCoreData = (ManagerCoreData *)[ManagerCoreData sharedInstance];
NSManagedObjectContext * managedObjectContex = managerCoreData.managedObjectContext;
SubMenu * newSubMenu =(SubMenu*) [NSEntityDescription insertNewObjectForEntityForName:@"SubMenu" inManagedObjectContext:managedObjectContex];

[self.menu addSubMenuObject:newSubMenu];

if (newSubMenu != nil){

    newSubMenu.name = self.textFieldName.text;
    newSubMenu.cost = [NSNumber numberWithInteger:[self.textFieldCost.text integerValue]];
    newSubMenu.about = self.textFieldAbout.text;
    newSubMenu.imageOriginal = self.imageView.image;

          NSError * savingError = nil;
    if ([managedObjectContex save:&savingError]){
        [self.navigationController popViewControllerAnimated:YES];
    }else {
        NSLog(@"Failed to save manager object contex!!!Error %@",savingError);

    }
}else {
    NSLog(@"Failed to create new object!!!");
}



@class SubMenu;

@interface Menu : NSManagedObject

@property (nonatomic, retain) NSData * imageMiddle;
@property (nonatomic, retain) id imageOriginal;
@property (nonatomic, retain) NSData * imageSmall;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSSet *subMenu;

@end

@interface Menu (CoreDataGeneratedAccessors)

- (void)addSubMenuObject:(SubMenu *)value;
- (void)removeSubMenuObject:(SubMenu *)value;
- (void)addSubMenu:(NSSet *)values;
- (void)removeSubMenu:(NSSet *)values;

@end

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[SubMenu 菜单]:无法识别的选择器发送到实例 0x74caf90”

4

0 回答 0