0
votes

I am trying to change the callout view of a pin. I use a .xib which contains a label and an image and it should appear when the user taps an annotation.

I use this code:

func mapView(mapView: MKMapView!, didSelectAnnotationView annotation: MKAnnotationView!) -> UIView!
    {
        println("delegate")
        let pin = annotation as! CustomPointAnnotation

    if let infoView = UIView.viewFromNibName("AnnInfoView") as? AnnInfoView {
        infoView.nameLabel.text = pin.title

        if let photo = pin.imageName {
            infoView.placePhoto.image = UIImage(named: photo)
        } else {
            infoView.placePhoto.image = UIImage(named: "generic")
        }

        return infoView
    } else {
        return nil
    }
}

The problem is that I get this error:

Objective-C method 'mapView:didSelectAnnotationView:' provided by method 'mapView(:didSelectAnnotationView:)' conflicts with optional requirement method 'mapView(:didSelectAnnotationView:)' in protocol 'MKMapViewDelegate'

and can't find a solution.

I use a this Objective-C library: https://github.com/RVLVR/REVClusterMap which clusters the annotations.

I have found in a file of this library this method:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    if( [delegate respondsToSelector:@selector(mapView:didSelectAnnotationView:)] )
    {
        [delegate mapView:mapView didSelectAnnotationView:view];
    }
}

but even if I comment it the error still won't disappear :(

What am I doing wrong?

Thank you!

1
In objective-C the method has a return type void and you have a View!. So it's not the same method.Stefan Salatic
Thanks Stefan. I tried using this method from an app that uses google maps. Thought it would workAndrei Dobrin

1 Answers

3
votes

The delegate method didSelectAnnotationView of MKMapViewDelegate does not have return value. Change this line

func mapView(mapView: MKMapView!, didSelectAnnotationView annotation: MKAnnotationView!) -> UIView!

to

func mapView(mapView: MKMapView!, didSelectAnnotationView annotation: MKAnnotationView!)