iosswiftmkmapviewmkmapviewdelegate

Class is not key value coding-compliant for the key in Swift


I have a MapKit app with several annotations. When tapped the annotations go to the following page.

Image one

I want the 'Open in Maps' button to take the co-ordinates from the Annotation and the user's current location (already being tracked) and open the Map application giving directions to the Pin.

I have tried this using the following:

 @IBAction func map_button(_ sender: AnyObject) {
    let elephant = CLLocationCoordinate2DMake(-39.069150, 174.081657)
    let elephant_place = MKPlacemark(coordinate:elephant)
    let mapItem = MKMapItem(placemark:elephant_place)
    let options = [MKLaunchOptionsDirectionsModeKey:
        MKLaunchOptionsDirectionsModeDriving]

    mapItem.openInMaps(launchOptions: options)

}

But once the MKAnnotation is clicked on it states this class is not key value coding-compliant for the key map_button.

I have attached my full code paste for the Info Page/Annotation Segue and Map View enter image description here

Thanks for your help


Solution

  • In your case, seems you select only map_button. please select View controller and then check in connection inspector. there You may have a bad connection in your Controller. Delete this bad connection and then try

    enter image description here