首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在尝试将elapsedTime保存到coreData

正在尝试将elapsedTime保存到coreData
EN

Stack Overflow用户
提问于 2013-01-30 07:01:08
回答 1查看 102关注 0票数 0

我的应用程序的一个核心功能是允许用户跟踪在某个位置花费的时间。然而,我遇到了一个(显然)严重的错误。我有两个核心数据实体:用于保存用户位置的Location和用于保存在该位置经过的时间的TimeSpentStudying (多对多关系)。我附上一张截图,让它更清晰:

http://i.imgur.com/C4VsWK2.png?1

下面是我的TimeSpentStudying类:

代码语言:javascript
复制
#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

代码语言:javascript
复制
-(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];
  }
  }
}

当我启动计时器时-收到这个错误:

代码语言:javascript
复制
<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'

下面是我认为导致错误的方法:

代码语言:javascript
复制
-(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的信息,请让我知道,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2013-01-30 09:26:14

错误在这里:

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

你在TimeSpentStudying类的一个对象上调用"coordinate“,而这个对象并没有实现这个方法,这会导致应用程序崩溃。

由于我在您发布的任何代码中都没有看到坐标,并且您说您的另一个实体类型是location,它可能包含一个坐标,所以您可能正在传递一个您想要传递timespentstudying的位置。你在使用ARC吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14593669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档