gpt4 book ai didi

iphone - CoreData : error: Serious application error. 核心数据更改处理期间捕获到异常

转载 作者:技术小花猫 更新时间:2023-10-29 10:38:14 28 4
gpt4 key购买 nike

我在开发我的 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)

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

我设置了一个 mapView,当用户点击 mkannotationview 上的详细信息披露按钮时,会弹出一个新 View (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 中的 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;
}
}}

我为粗略的语法道歉,我只是习惯了 SO,如果您需要更多代码,请告诉我,谢谢大家。

最佳答案

我有同样的错误,由于

-(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。

关于iphone - CoreData : error: Serious application error. 核心数据更改处理期间捕获到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14134808/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com