2012-10-24 43 views
1

好奇,如果有人能有一點幫助:如何刪除所有註釋銷然後添加一個新

我只是想告訴Xcode的是,如果在地圖上都存在「addAnnotation」和「newAnnotation」銷同時,刪除最初的「newAnnotation」引腳。

我不工作的代碼如下:

if ([self.mapView addAnnotation:addAnnotation] & [self.mapView addAnnotation:newAnnotation] return) 
{ 
    [self.mapView removeAnnotation:newAnnotation]; 
} 

謝謝!

+0

代替'&''放&&' – artapet

+0

謝謝,但任何想法如何讓Xcode的承認呢?它看起來像把'返回'在最後不工作... – Greg

+0

看起來像是如果語句工作有一個輕微的誤解:
'if(logical_expression_is_valid)do_something;'
返回沒有什麼可做的,可能你的想法是:
'if([self.mapView addAnnotation:addAnnotation]&[self.mapView addAnnotation:newAnnotation]) {self.mapView removeAnnotation:newAnnotation]; return; } ' – artapet

回答

6

感謝你的反饋,但我這個解決它:

NSArray *existingpoints = mapView.annotations; 

if ([existingpoints count]) 
    [mapView removeAnnotations:existingpoints]; 
+0

這不符合你最初的要求。如果只有一個引腳,它只會刪除一個引腳。如果兩個引腳都在註釋列表中,它什麼也不做。 – Craig

+0

它適合我。我有兩種不同的引腳類型:「添加」和「新」。因爲我只在地圖上加載了一個pin來啓動(例如「new」),所以它刪除了這個,並且我有[self.mapView addAnnotation:addAnnotation];立即調用以取代它。 – Greg

+0

我可以看到它適用於你想要的,但它沒有按照你的要求去做,所以這個問題對未來的開發者來說並沒有什麼用處。也許你可以改寫你的問題來匹配你實際想要滿足的條件:刪除所有註釋,然後再添加一個新註釋。 – Craig

相關問題