为什么我会收到此 NSManaged 对象错误
在 [theSelectedRoutine addExerciseObject:exercise];
行出现错误,提示未找到方法 -addExerciseObject。
界面: @property(非原子,保留)例程*theSelectedRoutine;
-(void)addExercise
{
if (managedObjectContext == nil)
{
managedObjectContext = [(CurlAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
[managedObjectContext retain];
}
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(exerciseChooser)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
NSError *error = nil;
Exercise *exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
exercise.name = selectedExercise;
[theSelectedRoutine addExerciseObject: exercise];
if (![managedObjectContext save:&error])
{
// Handle the error.
}
NSLog(@"%@", error);
[self.routineTableView reloadData];
}
..
Routine Class
#import "Routine.h"
#import "Exercise.h"
@implementation Routine
@dynamic name;
@dynamic timeStamp;
@dynamic routineExercises;
- (void)addRoutineExercisesObject:(Exercise *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"routineExercises"] addObject:value];
[self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)removeRoutineExercisesObject:(Exercise *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"routineExercises"] removeObject:value];
[self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)addRoutineExercises:(NSSet *)value {
[self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
[[self primitiveValueForKey:@"routineExercises"] unionSet:value];
[self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
}
- (void)removeRoutineExercises:(NSSet *)value {
[self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
[[self primitiveValueForKey:@"routineExercises"] minusSet:value];
[self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
}
@end
Getting error at line [theSelectedRoutine addExerciseObject: exercise];
saying method -addExerciseObject not found.
Interface:
@property (nonatomic, retain) Routine *theSelectedRoutine;
-(void)addExercise
{
if (managedObjectContext == nil)
{
managedObjectContext = [(CurlAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
[managedObjectContext retain];
}
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(exerciseChooser)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
NSError *error = nil;
Exercise *exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
exercise.name = selectedExercise;
[theSelectedRoutine addExerciseObject: exercise];
if (![managedObjectContext save:&error])
{
// Handle the error.
}
NSLog(@"%@", error);
[self.routineTableView reloadData];
}
..
Routine Class
#import "Routine.h"
#import "Exercise.h"
@implementation Routine
@dynamic name;
@dynamic timeStamp;
@dynamic routineExercises;
- (void)addRoutineExercisesObject:(Exercise *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"routineExercises"] addObject:value];
[self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)removeRoutineExercisesObject:(Exercise *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"routineExercises"] removeObject:value];
[self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)addRoutineExercises:(NSSet *)value {
[self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
[[self primitiveValueForKey:@"routineExercises"] unionSet:value];
[self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
}
- (void)removeRoutineExercises:(NSSet *)value {
[self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
[[self primitiveValueForKey:@"routineExercises"] minusSet:value];
[self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我也没有看到
addExerciseObject
,它不应该是[theSelectedRoutine addRoutineExercisesObject:exercise];
吗?Well I don't see
addExerciseObject
either, shouldn't it be[theSelectedRoutine addRoutineExercisesObject:exercise];
?