2013-06-04 25 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