2014-09-29 75 views
0

我正在開發一款應用程序,其中農民將自定義註釋(帶有數字的針腳)放在他的作物中感興趣的點上,並將帶有屏幕截圖的報告通過電子郵件發送回他的辦公室,然後移動到他的下一個圍場。發送電子郵件的代碼MKAnnotation堅持使用舊信息

part screenshot of field of pins

部分包括重置屬性和歸零陣列和高德等他的第一場工作正常,但是POI在隨後就會失控的所有字段的編號。由錯誤引腳代表的數據是正確的,只是引腳本身不是(更多的是在一瞬間>> **)。

所以我已經確定沒有什麼錯什麼領導到一根針落地,我已經跟我的清除註釋:

[ self.mapView removeAnnotations:self.mapView.annotations]; 

蘋果文檔提到,一個也需要實現此方法在重置:

[ self.mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotation"]; 

因爲即使他們已經從屏幕上清除他們仍然存在於內存中。但是,這仍然不能解決我的問題。如果我明確地將我的註釋清除:

self.mapView.annotations = nil; 

問題仍然存在。註釋上的數字在第二個和第三個字段中隨機出現。通過記錄到屏幕上的textView,我可以看到保存POI編號的正確值的數組。有關CLLocation或MKAnnotation的東西仍然存在。 Apple的Class Reference中沒有關於如何重置CLLocationManager的內容,所以我認爲這是通過一個簡單的Start和Stop來完成的。我使用這些是正確的平衡,所以我沒有運行多個實例。

** >>下面是決定丟棄什麼針的片段中,動作發生在評論

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation(id<MKAnnotation>)annotation 
{ 
if([annotation isKindOfClass:[MKUserLocation class]]) 
    return nil; 

    static NSString *identifier = @"myAnnotation"; 
MKAnnotationView * annotationView = (MKAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 

if (!annotationView) 
{ 
    annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 


      // standard stuff up to here 
      // findings build up as a score of each test point. 

    if (contentScore == 0) 
    { 
      // a green asterisk marker if no score was achieved 

    annotationView.image = [UIImage imageNamed:@"markerZero.png"];  
    } else { 

      // the marker number comes from idx in SiteCount Array 

    str = [NSString stringWithFormat:@"marker%d.png",siteCount[idx]; 
    annotationView.image = [UIImage imageNamed:str]; 
    } 


} else { 
    annotationView.annotation = annotation; 
} 

return annotationView; 
} 

中間目前的解決辦法是帶離內存的主屏幕上的繁瑣工作並在開始下一場之前重新開始。我可以回到使用系統提供的紅色和綠色的針腳,但他被數字交叉引用報告而被寵壞了。

那麼我應該在哪裏看?誰是罪魁禍首?我懷疑MKAnnonation但我的知識已經用完了

+1

[在回答你以前的問題(和其他鏈接到的答案)](http://stackoverflow.com/questions/24215210/does-mkannotationview-buffer-its-input-queue)在這裏適用於這裏相同的方式。在viewForAnnotation中,代碼使用外部變量contentScore和idx,假定它們將與當前註釋參數同步。另外,視圖屬性只在創建時更新(所以出隊/重用視圖顯示舊的註釋圖像)。 – Anna 2014-09-29 12:23:05

+0

自從那個問題得到你的建議工作到我放棄歷史方面的時候,我花了整整一段時間,我遇到過數百個答案,它們使用變量來確定他們的引腳和OP的一些事情祝你快樂,噢,再次工作,我會在聖誕節前後回到你身邊,乾杯。 – aremvee 2014-09-29 12:36:52

+1

當然你可以使用變量來確定一些關於引腳的東西。但是這些變量必須與有問題的註釋直接相關,或者應該在創建視圖或取消出隊時應用代碼。在上面顯示的代碼中,idx不保證適用於當前註釋,並且僅在創建視圖時才應用。 – Anna 2014-09-29 12:40:33

回答

0

正如@Anna表示,如果一個可重複使用的視圖離隊你是不是完全重新初始化您的註解視圖 -

你應該有類似

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation(id<MKAnnotation>)annotation 
{ 
    if([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 

    static NSString *identifier = @"myAnnotation"; 

    MKAnnotationView * annotationView = (MKAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 

    if (!annotationView) { 
     annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
    }      //Note this closing brace! 

      // standard stuff up to here 
      // findings build up as a score of each test point. 

    if (contentScore == 0) { 
      // a green asterisk marker if no score was achieved 
     annotationView.image = [UIImage imageNamed:@"markerZero.png"];  
    } else { 
      // the marker number comes from idx in SiteCount Array 
     str = [NSString stringWithFormat:@"marker%d.png",siteCount[idx]; // As per @anna's comment I am not sure how you are managing this - It would be better if the number came from the associated annotation object 
     annotationView.image = [UIImage imageNamed:str]; 
    } 

    annotationView.annotation = annotation; 
} 
+0

aaaahhhh這解釋了爲什麼他們響了一天,並表示在他們的出擊期間,別針改變了數字。他們必須將視線滾動到屏幕邊界之外,並重新排列契約。是的,安娜在她的領域非常出色,尤其是當她在場上站穩腳跟的時候,尤其是她們;-) – aremvee 2014-09-29 13:05:50