CoreData:错误:严重的应用程序错误.在Core Data更改处理期间捕获到异常

Ox *_*ith 12 iphone core-data nsnotificationcenter nsmanagedobject ios

我正在遇到开发我的iPhone应用程序的主要问题.

这是完整的错误:

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)
Run Code Online (Sandbox Code Playgroud)

这很奇怪,因为我有两个coreData实体(Locations&TimeSpentStudying).但我不认为那些是问题.[TimeSpentStudying coordinate]很奇怪,因为我没有coordinateTimeSpentStudying核心数据类上发送过属性

我有一个mapView设置,当用户点击mkannotationview上的详细信息披露按钮时,会弹出一个新视图(LibraryTrackTimeViewController),但几乎无法使用.我尝试在viewDidLoad中调用NSLog,但没有出现任何内容.

mapViewController.m

#pragma mark - NSNotification

- (void)contextDidChange:(NSNotification *)notification
{
  if ([self isViewLoaded]) {
    [self updateLocations];
}
Run Code Online (Sandbox Code Playgroud)

.

- (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];
Run Code Online (Sandbox Code Playgroud)

}

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

我认为可能与mapViewController.m中的prepareForSegue方法有关

-(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;
  }
 }}
Run Code Online (Sandbox Code Playgroud)

我为粗略的语法道歉,我只是习惯了SO,如果你需要更多的代码,请让我知道,谢谢大家.

Dog*_*fee 7

我有同样的错误,因为

-(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;
Run Code Online (Sandbox Code Playgroud)

我用过indexPath而不是newIndexPath.


小智 1

根据项目的复杂性,捕获此问题的快速方法是实现有问题的方法并在那里设置断点。当您到达断点时,您可以看到它被调用的位置,而鲍勃是您的叔叔。

所以你可以把类似的东西

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

在你的TimeSpentStudying班级中看看它在哪里被调用。

只要确保完成后将其删除即可。