MKMapView中可能的错误 [英] Possible bug in MKMapView

查看:31
本文介绍了MKMapView中可能的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用地图视图创建ViewController,这是我添加到viewDidLoad的唯一代码:

If I create a ViewController with a map view and this is the only code I add to viewDidLoad:

MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(-90, -180);
[self.mapView addAnnotation:annotation];
[self.mapView removeAnnotation:annotation];
[annotation release];

我得到了错误:

An instance 0xa126fa0 of class MKPointAnnotation was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0xa127df0> (
<NSKeyValueObservance 0xa127c90: Observer: 0xa11c530, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0xa127640>

如果我将代码更改为此,则不会出现任何错误:

If I change the code to this then I don't get any errors:

MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(0, 0);
[self.mapView addAnnotation:annotation];
[self.mapView removeAnnotation:annotation];
[annotation release];

唯一的区别是(0,0)在地图上可见,而(-90,-180)在视图之外.也就是说,我需要平移地图才能使坐标(-90,-180)可见.

The only difference is that (0,0) is visible in the map, where as, (-90, -180) is out of view. That is, I need to pan the map to bring coordinate (-90, -180) into view.

任何人都曾经历过此错误,甚至更好地知道如何解决该错误?

Anyone experienced this error before or even better know how to fix it?

推荐答案

经过更多测试后,我确信这是MKMapView中的错误.我通过仅添加可见区域中的注释来解决此问题.更多工作,但至少不会使我的应用程序崩溃:)

After some more testing I'm convinced it is a bug in MKMapView. I worked around it by only adding annotations that are in the visible region. More work but at least it doesn't crash my app :)

这篇关于MKMapView中可能的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆