私のアプリの中心的な機能は、ユーザーがその場所で過ごした時間を追跡できるようにすることです。ただし、(明らかに) 重大なエラーが発生しています。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
オブジェクトに複数のTimeSpentStudying
timeIntervals を保存したい (日付、timeSpent など)。私が十分に明確であることを願っています。もっと見る必要がある場合はLibraryTrackTimeViewController
、お知らせください。よろしくお願いします。