2013-01-03 22 views
9

我遇到了开发我的iphone应用程序的主要问题。CoreData:错误:严重的应用程序错误。核心数据更改处理期间发生异常

这里是完整的错误:

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 0x21db92d0 with userInfo (null) 

这是奇怪,因为我有两个coreData实体(位置& TimeSpentStudying)。但我不认为这是问题。 [TimeSpentStudying coordinate]是奇怪的,因为我不会对TimeSpentStudying核心数据类发送的coordinate属性不

我有一个MapView的设置,并且当用户点按详细公开内容按钮上的mkannotationview,一个新的视图(LibraryTrackTimeViewController)啪啪但是几乎不可用。我试图在viewDidLoad中调用NSLog并没有显示出来。

mapViewController.m

#pragma mark - NSNotification 

- (void)contextDidChange:(NSNotification *)notification 
{ 
    if ([self isViewLoaded]) { 
    [self updateLocations]; 
} 

- (void)updateLocations 
{ 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Location" inManagedObjectContext:self.managedObjectContext]; 

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
[fetchRequest setEntity:entity]; 

NSError *error; 
NSArray * foundObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error]; 
    if (foundObjects == nil) { 
    FATAL_CORE_DATA_ERROR(error); 
    return; 
    } 

    if (locations != nil) { 
    [self.mapView removeAnnotations:locations]; 
    } 

locations = foundObjects; 
[self.mapView addAnnotations:locations]; 

}

-(void)dealloc 
{ 
[[NSNotificationCenter defaultCenter] removeObserver:self 
    name:NSManagedObjectContextObjectsDidChangeNotification 
    object:self.managedObjectContext]; 
} 

我认为错误可能在mapViewController.m

-(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; 
    } 
}} 

我的粗略语法道歉与prepareForSegue方法做,我只是习惯到如此,如果你需要更多的代码,请让我知道,谢谢大家。

+0

嗨,欢迎您!另外,很好的问题! – doge

+3

错误消息清楚地表明'坐标'消息被发送到'TimeSpentStudying'的一个实例,可能是地址为0x21db92d0的对象。所以在某些时候,你正在使用一个'TimeSpentStudying'对象来预期不同的类型('Locations'?)。由于Objective-C中的动态方法解析,这些问题通常只在运行时才会显示出来。您应该尝试找出问题,例如通过设置所有Objective-C异常的断点。 –

回答

1

根据您的项目的复杂性,快速的方法来抓住这个是实现违规方法并在那里设置断点。当你点击断点时,你可以看到它被称为的位置,而鲍勃是你的叔叔。

所以你可以把类似

- (CLLocationCoordinate2D)coordinate{ 
    // set a breakpoint on the next line 
    NSParameterAssert(false); 
    return nil; 
} 

TimeSpentStudying类,看看它被调用。

只要确保在完成后删除它。

-3

我会尝试的东西的组合。

  1. 从模拟器中删除应用程序并清理应用程序并再次运行。

  2. 看着你的代码,我觉得你正在将managedContextObject从一个控制器传递到另一个控制器,不需要那样做。用户AppDelegate sharedInstance可以随时获得managedObject。它不会创建多个实例,它是一个单例对象。

试试这两个,希望你可能会找到一些答案或可能会解决它。

+1

投票下来的B/C你实际上从来不想用Core Data来做这件事,并且总是使用苹果公司推荐的“传递接力棒”的方式传递MOC。 – bpapa

4

我有同样的错误,由于

-(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath 

case NSFetchedResultsChangeInsert: 
      //[self.tableView insert 
      NSLog(@"change insert"); 
      [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
      break; 

我已经使用indexPath代替newIndexPath。

+0

谢谢道格,你救了我的培根 –

2

通过取消分配提取的结果控制器来解决该问题。它仍然执行提取,因为我在单独的屏幕中添加/编辑对象。

相关问题