【发布时间】:2017-03-28 08:57:37
【问题描述】:
我已经寻找了几天试图删除标题等于或不等于从另一个视图控制器的 uicollection 视图单元 didSelect 中选择的字符串的注释。我将字符串传递给包含我的地图视图的视图控制器。我使用自定义注释,它是注释显示方式的模型。
如何按标题选择和删除自定义注释。我已经有一个字典数组,其中包含删除其他注释后注释将使用的数据。我知道如何删除所有注释,但不知道如何仅删除标题等于/不等于搜索字符串的注释。
为什么 swift 3 没有这样的功能?
我想出了这个,但只删除了注释并显示了“filteredAnnotations”
var filteredAnnotations = self.mapview.annotations.filter {($0.title != nil) && isEqual(searchString) }
print(filteredAnnotations)
self.mapview.removeAnnotations(self.mapview.annotations)
self.mapview.addAnnotations(filteredAnnotations)
使用 print 语句只返回一个空数组“[]”
【问题讨论】:
-
让filteredAnnotations = mapview.annotations.filter {注解 if let title = annotation.title, title != searchString { return true } return false } mapview.removeAnnotations(filteredAnnotations)
标签: swift search filter annotations title