我有错误:
[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属性的新事件,但我有这个错误而且我不明白错误..
答案 0 :(得分:0)
问题是您尝试发送NSManagedObject
init
条消息。
您需要使用- (id)initWithEntity: (NSEntityDescription *) entity insertIntoManagedObjectContext: (NSManagedObjectContext *) context