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

问题描述 投票:0回答:1

我似乎无法锻炼为什么在点击地图上的注释时没有调用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")
    }

任何帮助欣赏。

ios swift mapkit
1个回答
1
投票

校验

class FindPeopleNearbyViewController: MKMapViewDelegate {

mapView.delegate = self
© www.soinside.com 2019 - 2024. All rights reserved.