2017-12-30 18 views
0

マップ上の注釈がタップされたときに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") 
    } 

助けてください。

+0

あなたは、自己にあなたのMapViewのデリゲートを設定しましたか? – Honey

+0

Nope。やあ!ありがとう、私はそれがそれのような何か愚かだったことを知っていた。 –

答えて

1

チェック

class FindPeopleNearbyViewController: MKMapViewDelegate { 

mapView.delegate = self 
関連する問題