2011-10-31 19 views
0

我正在開發一個應用程序,我需要在同一時間顯示多個事件的位置,我有兩種類型的事件(我的事件和所有事件)。我有機會通過細分控制在我的活動和所有活動之間切換,首先顯示所有活動的位置,當用戶切換到我的活動時,它將刪除或隱藏所有活動位置(活動針),並在相同的地圖視圖中顯示活動位置的活動針。我有點混淆如何處理這個問題,以重新加載或刷新地圖視圖與新的引腳?用新的引腳重新加載mapView iphone dev?

回答

3

你可以試試這個...

//Remove or hide all annotations 
for (id annotation in mapView.annotations) { 
    if (annotation != mapView.userLocation) { 
     [[mapView viewForAnnotation:annotation] setHidden:YES]; // You can remove as well 
    } 
} 

/代碼刪除,而不是躲在/

NSMutableArray *listRemoveAnnotations = [[NSMutableArray alloc] init]; 
for (id annotation in mapView.annotations) { 
    if (annotation != mapView.userLocation) { 
     [listRemoveAnnotations addObject:annotation]; 
    } 
} 
[mapView removeAnnotations:listRemoveAnnotations]; 
[listRemoveAnnotations release]; 

當所有註釋處理則註釋:

  • 如果所有註釋都隱藏,請取消隱藏您希望顯示的註釋。
  • 如果刪除所有註釋,請添加您希望顯示的註釋。