2013-06-04 90 views
-1

我有一个调用addAnnotation恰好3次(验证坐标是用好CLLocationCoordinate2DIsValid,传递了一个模型,响应idtitlelatitudelongitudecoordinate后的应用程序。在该模型,我在我的coordinate方法做一个NSLog看回调MapKit寻找更多的注解比我指定

注意coordinatename作为方法来实现,虽然这应该没有什么区别,右

我期待什么:?

MapKit将访问坐标法3次

我能得到什么:

MapKit访问的坐标3次,每次协调,然后尝试第4的时候,即使没有4坐标和应用程序崩溃在内存异常上,结果是nil

我对MapKit相当幼稚,但必须对此有所解释。

任何帮助表示赞赏!

+0

请提供一些代码,特别是您从 –

回答

1

如果用户位置显示在您的地图上(蓝色圆点),您将有四个注释,因为蓝色圆点也是一个注释。

您的应用程序可能崩溃的用于显示用户所在地的注解没有叫coordinate

方法来防止你的代码来调用方法coordinate您可以检查检索到的注释是你的自定义注解的实例类:

if ([annotion isKindOfClass:[YourCustomeAnnotation class]]) 
    // it's one of your annotations 
else 
    // it's the current location annotation 

或检查当前的注释是当前位置anotation

if ([annotion isKindOfClass:[MKUserLocation class]]) 
    // it's the current location annotation 
else 
    // it's one of your annotations 
+0

调用'addAnnotation'的方法。如何检测此内容并使模型不响应?对不起,我没有提供示例代码,但它是用RubyMotion编写的,我几乎准备好在Objective-C中重写它,看看我能否以这种方式重新编写代码。 –

+0

@SteveRoss我编辑了我的答案,包括相同的代码 – pre