2016-01-13 97 views
0

在我的Swift應用程序中,我按照本教程向我的mapview添加了自定義的針腳和標註。我的代碼幾乎完全一樣:https://github.com/wircho/CustomMapViewCallout從MapPin中刪除子視圖

每隔幾分鐘,我試圖通過清除當前註釋和標註刷新地圖數據。

我的針類是CustomPin,我的標註類是CustomCallout。

我曾嘗試:

for subview in self.view.subviews { 
      if (subview is CustomPin) { 
       print(subview) 
       subview.removeFromSuperview() 
      } 
     } 

但這不是我消除了針。如何從我的mapview中刪除我的pin和callout子視圖?

回答

1

您可以創建一個計時器並將其設置爲5分鐘,然後調用一個函數來刪除您的針腳。

var timer = NSTimer() 

在你viewDidLoad組此行

// 300 is 5 minutes 
timer = NSTimer.scheduledTimerWithTimeInterval(300, target: self, selector: Selector("removePins"), userInfo: nil, repeats: true) 

迭代通過你的註釋和刪除它們

func removePins(){ 
    for annotation in mapView.annotations as [MKAnnotation] { 
     mapView.removeAnnotation(annotation) 
    } 
} 
+0

能否請您看看這個問題:http://stackoverflow.com /問題/ 34889659 /連接滑塊到視圖迅速 –