0

我的应用程序的一个核心功能是允许用户跟踪在某个位置花费的时间。但是,我遇到了(显然)一个严重的错误。我有两个核心数据实体: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我是否必须专门为我创建全新的 managedObject 上下文TimeSpentStudying?我希望每个Location对象都TimeSpentStudying保存多个 timeIntervals(日期、timeSpent 等)。我希望我说得足够清楚。如果您需要查看更多内容LibraryTrackTimeViewController- 请告诉我,谢谢!

4

1 回答 1

1

错误在这里:

BooksonBooksonBooks[18856:907] -[TimeSpentStudying 坐标]:无法识别的选择器发送到实例 0x1e441130

您在 TimeSpentStudying 类的对象上调用“坐标”,它没有实现该方法,这导致应用程序崩溃。

由于我在您发布的任何代码中都没有看到坐标,并且您说您的其他实体类型是位置,它可能包含一个坐标,因此您可能正在传递一个您打算通过时间花费学习的位置。你在用ARC吗?

于 2013-01-30T01:26:14.477 回答