【问题标题】:[iOS][MagicalRecord][CoreData] Data handling[iOS][MagicalRecord][CoreData] 数据处理
【发布时间】:2013-04-28 10:27:41
【问题描述】:

iOS 地图应用程序出现问题。 我认为它来自同时对相同数据的并发访问。 但错误并不明确。

应用是什么:

  • 当用户更新他的位置时添加位置记录。 (LocationManager)
  • 在地图上显示位置(MapViewController

如果我不添加任何位置,我不会收到任何错误。 如果我添加一个并同时显示地图(使用来自 MagicalRecord 的位置记录),我会收到此错误或访问错误:

错误:* 由于未捕获的异常“CALayerInvalidGeometry”而终止应用程序,原因:“CALayer 位置包含 NaN:[nan -2.60432e+07]”

这是该错误的屏幕记录:Screen recording

我在主线程上执行了所有数据操作进行了测试,我仍然无法找出错误

如果有人可以帮助我,他会拯救我的一天。

谢谢。

【问题讨论】:

  • 对不起,我没有关注。请再次说明你想要什么,你有什么
  • 错误提示您正在尝试使用 NAN(不是数字)设置框架或位置或其他内容。

标签: ios core-data map magicalrecord


【解决方案1】:

问题的直接原因不太可能是并发错误处理,因为所有与 ui 相关的方法都应该在主线程上调用,尽管它可能是根本原因。现在,正如错误所说,发生的事情是CALayer 位置坐标在某个时候设置为NaN。这通常是因为除以零而发生的。要找出它发生的位置,请启用异常断点。当你看到哪个层抛出异常时,看看它的xyNaN,如果是,看看你在哪里设置NaN

【讨论】:

  • 我检查了所有用于在地图上显示东西的值,也使用了断点。
【解决方案2】:

位置管理器:

- (void)setupLocationRecord:(CLLocation *)location {
LocationRecord *locationRecord = [LocationRecord createEntity];

locationRecord.latitude = [NSNumber numberWithDouble:location.coordinate.latitude];
locationRecord.longitude = [NSNumber numberWithDouble:location.coordinate.longitude];
locationRecord.createdAt = [NSDate date];
locationRecord.updatedAt = [NSDate date];

[[NSManagedObjectContext defaultContext] saveNestedContexts];

//[self performSelectorInBackground:@selector(addLocation:) withObject:locationRecord];
[locationRecord debug];
[self addLocation:locationRecord];

}

地图视图控制器:

- (void)setupMap {
NSArray *array = [LocationRecord findAllSortedBy:@"idLocation" ascending:YES];
NSLog(@"%s %@", __PRETTY_FUNCTION__, array);
self.mapView.locationsRecordList = [[NSMutableArray alloc] initWithArray:array];

}

【讨论】:

  • 这应该是对您的问题的编辑,而不是答案。 (这不是论坛。)
猜你喜欢
  • 2016-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-22
  • 1970-01-01
相关资源
最近更新 更多