0

我有错误:

[2194:c07] CoreData: error: Failed to call designated initializer on NSManagedObject class 'Event' 
2012-12-08 12:00:57.505 eventCost[2194:c07] -[Event setType:]: unrecognized selector sent to instance 0x7456dd0
2012-12-08 12:00:57.523 eventCost[2194:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Event setType:]: unrecognized selector 

我的 addEventController:@protocol 有协议

AddEventControllerDelegate
- (void) addEventControllerDidSave:(NSString *) typeText;
- (void) addEventControllerDidCancel:(Event *) personToDelete;
@end

协议的实现:

- (void) addEventControllerDidCancel:(Event *)EventToDelete{

    [[self currentPerson] removeEventsObject:EventToDelete];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void) addEventControllerDidSave:(NSString *)typeText{

    Event *newEvent = [[Event alloc]init];
    [newEvent setType:typeText];

    [currentPerson addEventsObject:newEvent];
    [self dismissViewControllerAnimated:YES completion:nil];
}

我也有这个添加新事件的segue:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([[segue identifier]isEqualToString:@"addEvent"])
    {
        AddEventController *aec = (AddEventController *) [segue destinationViewController];
        aec.delegate = self;
    }
}

我只是尝试使用 type 属性添加新事件,但我有这个错误,我不明白什么问题..

4

1 回答 1

0

问题是您正在尝试发送NSManagedObject消息init

你需要使用- (id)initWithEntity: (NSEntityDescription *) entity insertIntoManagedObjectContext: (NSManagedObjectContext *) context

在此处查看文档:https ://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/NSManagedObject.html

于 2013-04-11T20:34:18.033 回答