0

私のアプリの中心的な機能は、ユーザーがその場所で過ごした時間を追跡できるようにすることです。ただし、(明らかに) 重大なエラーが発生しています。Locationユーザーの場所TimeSpentStudyingを保存するためと、その場所での経過時間を保存するため (多対多の関係) の2 つのコア データ エンティティがあります。わかりやすくするためにスクリーンショットを添付しています。

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特に forで新しい managedObject コンテキスト全体を作成する必要がありますTimeSpentStudyingか? 各Locationオブジェクトに複数のTimeSpentStudyingtimeIntervals を保存したい (日付、timeSpent など)。私が十分に明確であることを願っています。もっと見る必要がある場合はLibraryTrackTimeViewController、お知らせください。よろしくお願いします。

4

1 に答える 1

1

エラーはここにあります:

BooksonBooksonBooks [18856:907]-[TimeSpentStudying座標]:認識されないセレクターがインスタンス0x1e441130に送信されました

TimeSpentStudyingクラスのオブジェクトで「coordinate」を呼び出しています。このオブジェクトはそのメソッドを実装していないため、アプリが爆発します。

あなたが投稿したどのコードにも座標が表示されておらず、他のエンティティタイプは場所であり、おそらく座標が含まれているとのことなので、おそらく、時間を費やした調査を通過する予定の場所を通過していることになります。ARCを使用していますか?

于 2013-01-30T01:26:14.477 に答える