点击注释时不会处理委托功能

时间:2017-12-30 02:09:28

标签: ios swift mapkit

我似乎无法解决为什么在点击地图上的注释时未调用MKMapViewDelegate函数的原因。

这是我的代码。我希望在敲击引脚时调用最后一个函数calloutAccessoryControlTapped。但它不起作用。

class FindPeopleNearbyViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    var locationManager : CLLocationManager!
    @IBOutlet weak var mapView : MKMapView!

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        determineCurrentLocation()
    }

    func determineCurrentLocation()
    {
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()

        if CLLocationManager.locationServicesEnabled() {
            locationManager.startUpdatingLocation()
        }
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let userLocation:CLLocation = locations[0] as CLLocation

        let center = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.0025, longitudeDelta: 0.0025))

        mapView.setRegion(region, animated: true)

        // Drop a pin at user's Current Location
        let myAnnotation: MKPointAnnotation = MKPointAnnotation()
        myAnnotation.coordinate = CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude);
        myAnnotation.title = "My location"

        mapView.addAnnotation(myAnnotation)

        self.locationManager.stopUpdatingLocation()
    }

    internal func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
        print("In annotation calloutAccessoryControlTapped")
    }

任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

检查

class FindPeopleNearbyViewController: MKMapViewDelegate {

mapView.delegate = self
相关问题