我的应用程序的一个核心功能是允许用户跟踪在某个位置花费的时间。然而,我遇到了一个(显然)严重的错误。我有两个核心数据实体:用于保存用户位置的Location和用于保存在该位置经过的时间的TimeSpentStudying (多对多关系)。我附上一张截图,让它更清晰:
http://i.imgur.com/C4VsWK2.png?1
下面是我的TimeSpentStudying类:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class Location;
@interface TimeSpentStudying : NSManagedObject
@property (nonatomic, retain) NSString * libraryNameText;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSNumber * timeSpent;
@property (nonatomic, retain) Location *info;
@end在这里,我将Location实体传递给将跟踪已用时间的viewController - LibraryTrackTimeViewController:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (distance < 500) {
if ([segue.identifier isEqualToString:@"TrackLibraryTimes"]) {
UINavigationController *navigationController = segue.destinationViewController;
LibraryTrackTimeViewController *controller = (LibraryTrackTimeViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
controller.libraryNameText = [[[mapView selectedAnnotations] objectAtIndex:0] title];
}
}
}当我启动计时器时-收到这个错误:
<TimeSpentStudying: 0x1e441130> (entity: TimeSpentStudying; id: 0x1d5a4260 <x-coredata:///TimeSpentStudying/t3B884C6F-8210-4B9E-A716-23DEC24291482> ; data: {
date = nil;
info = nil;
libraryNameText = nil;
timeSpent = 0;
})
2013-01-29 17:46:25.885 BooksonBooksonBooks[18856:907] -[TimeSpentStudying coordinate]: unrecognized selector sent to instance 0x1e441130
2013-01-29 17:46:25.892 BooksonBooksonBooks[18856:907] CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[TimeSpentStudying coordinate]: unrecognized selector sent to instance 0x1e441130 with userInfo (null)
2013-01-29 17:46:25.899 BooksonBooksonBooks[18856:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TimeSpentStudying coordinate]: unrecognized selector sent to instance 0x1e441130'下面是我认为导致错误的方法:
-(IBAction)startTimer:(id)sender
{
startTime = [[NSDate alloc] init];
elapsedTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
TimeSpentStudying *timeSpentStudying = [NSEntityDescription insertNewObjectForEntityForName:@"TimeSpentStudying" inManagedObjectContext:self.managedObjectContext];
timeSpentStudying.timeSpent = [NSNumber numberWithDouble:totalTimeSpentStudying];我不太理解这个错误。我是否必须在我的LibraryTrackTimeViewController中专门为TimeSpentStudying创建全新的managedObject上下文?我希望每个Location对象都保存了多个日期( TimeSpentStudying timeIntervals,timeSpent等)。我希望我说得够清楚了。如果您需要了解更多关于LibraryTrackTimeViewController的信息,请让我知道,谢谢!
发布于 2013-01-30 09:26:14
错误在这里:
BooksonBooksonBooks18856:907 -TimeSpentStudying坐标:无法识别的选择器发送到实例0x1e441130
你在TimeSpentStudying类的一个对象上调用"coordinate“,而这个对象并没有实现这个方法,这会导致应用程序崩溃。
由于我在您发布的任何代码中都没有看到坐标,并且您说您的另一个实体类型是location,它可能包含一个坐标,所以您可能正在传递一个您想要传递timespentstudying的位置。你在使用ARC吗?
https://stackoverflow.com/questions/14593669
复制相似问题