我一定在这里缺少明显的东西.....
作品:
从核心数据添加一堆MKPointAnnotations ...显示在地图上
不起作用:
轻按图钉时,尝试使打印语句出现。
我设置了MKMapView Delegate,并且没有实现AnnotationView,因为我希望在敲击引脚后立即进行查询。宁愿不显示上下文对话框。
缺少识别针脚的提示,我想念什么?
import UIKit
import MapKit
import Foundation
import CoreData
class MapViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapOutlet: MKMapView!
var latitude = 100.0 as Double
var longitude = 120.0 as Double
var pins = [NSManagedObject]()
func pullPins() {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = appDelegate.managedObjectContext
let fetchRequest = NSFetchRequest(entityName: "Pin")
do {
let results = try managedContext.executeFetchRequest(fetchRequest)
pins = results as! [NSManagedObject]
for pin in pins {
let pinLat = pin.valueForKey("latitude") as! Double
let pinLon = pin.valueForKey("longitude") as! Double
let pinCoordinate = CLLocationCoordinate2D(latitude: pinLat, longitude: pinLon)
let annotation = MKPointAnnotation()
annotation.coordinate = pinCoordinate
self.mapOutlet.addAnnotation(annotation)
}
}
catch let error as NSError {
print("Could not fetch \(error), \(error.userInfo)")
}
}
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
print("Pin Tapped")
}
override func viewDidLoad() {
super.viewDidLoad()
pullPins()
}
}
最佳答案
如果您没有收到地图视图委托消息,那是因为您尚未使自己成为地图视图的委托。例如:
self.mapOutlet.delegate = self
关于ios - Swift:MapKit-识别Pin Tap,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38667845/