2016-01-13 105 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 /连接滑块到视图迅速 –