Reputation: 5
I know there was a question about this before. However, I think a little bit noob because I can't get it solved.
I'm getting that error when trying this:
MKAnnotation *annotation = [[MKAnnotation alloc] initWithCoordinate:coordenada title:@"HELLO!"];
[mapa addAnnotation:annotation];
I also have the following method:
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation
{
MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapa dequeueReusableAnnotationViewWithIdentifier: @"asdf"];
if (pin == nil)
{
pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"asdf"] autorelease];
}
else
{
pin.annotation = annotation;
}
pin.pinColor = MKPinAnnotationColorRed;
pin.animatesDrop = YES;
return pin;
}
And did the #import < MapKit/MKAnnotation.h>
in header.
Any help please?
Thank you very much!
Upvotes: 0
Views: 2677
Reputation:
MKAnnotation
is a protocol, not a class that you can instantiate.
Have you defined your own class that implements MKAnnotation
and a initWithCoordinate:title:
method? If you have, use that class name and import its header file.
If you haven't created your own annotation class, you'll have to create one or you can use the pre-defined MKPointAnnotation
class (in iOS 4+) instead:
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = coordenada;
annotation.title = @"HELLO!";
[mapa addAnnotation:annotation];
[annotation release];
You'll also need to do the following:
#import <MapKit/MapKit.h>
at the top of the filedelegate
property (or outlet in IB) of the map view otherwise viewForAnnotation
won't get calledUpvotes: 6