【发布时间】:2017-06-16 00:17:28
【问题描述】:
我正在基于 coredata 将注释存储并加载到地图上。
我不确定如何点击注释并删除该引脚的核心数据。
与 tableview 不同,没有真正的 indexPath 可以从我的 fetched objects 数组中删除。我能想到的在屏幕上跟踪我的注释的唯一方法是给它们一个标签并将其与我获取的结果数组对齐,但我觉得必须有更好的方法。
我知道如何实现对 pin 的点击,但是一旦我选择了 pin,我如何将它与创建它的 coredata 对象联系起来?
func loadPins(){
let pinRequest : NSFetchRequest<Pin> = Pin.fetchRequest()
do {
pins = try managedObjectContext.fetch(pinRequest)
} catch {
print("There was en error fetching pins")
}
for pin in pins {
let lat = pin.latitude
let lon = pin.longitude
let coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)
createAnnotation(coordinate: coordinate)
}
}
func createAnnotation(coordinate : CLLocationCoordinate2D){
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotation.title = "henlo"
map.addAnnotation(annotation)
}
【问题讨论】:
标签: ios swift core-data mkannotation