must implement title when canShowCallout is YES
Asked Answered
J

1

8

I'm getting this exception when trying to show the callout on my map annotation, even if the title is set.

This is the init method I'm using in my MapAnnotation class:

- (id)initWithTitle:(NSString *)ttl subtitle:(NSString *)sub andCoordinate:(CLLocationCoordinate2D)c2d {
    titles = ttl;
    coordinate = c2d;
    subtitle = sub;
    return self;
}

Then, somewhere in another class I'm creating the annotations (2 in two different methods):

MapAnnotation *annotation = [[MapAnnotation alloc] initWithTitle:[formatter stringFromDate:sourceDate] subtitle:@"test" andCoordinate:CLLocationCoordinate2DMake(point.latitude, point.longitude)];
[self.mapView addAnnotation:annotation];

And this is the annotations method:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    if (annotation == mapView.userLocation)
        return nil;

    static NSString *s = @"ann";
    MKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:s];
    if (!pin) {
        pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:s];
        pin.canShowCallout = YES;
        pin.image = [UIImage imageNamed:@"pin.png"];
        pin.calloutOffset = CGPointMake(0, 0);
    }
    return pin;
}

Another thing I'd like to do is use two different images for the two map annotations. Any idea?

Thanks.

Jeanicejeanie answered 24/12, 2013 at 9:51 Comment(4)
what error are you getting?Ricoricochet
@Ricoricochet the one in the question's title.Jeanicejeanie
there is no error message or anythingRicoricochet
if the title is your error message, then the meaning seems clear enough :DRicoricochet
W
11

you MapAnnotation should contain title property, not titles for map callout to work. Declare it as follows

@property (nonatomic, copy) NSString *title;
Woodborer answered 24/12, 2013 at 10:2 Comment(6)
pin is a MKAnnotationView object, there's no title property for it.Jeanicejeanie
my MapAnnotation does contain a title property.Jeanicejeanie
No, it is named as titles not title as you have posted in your question above.Woodborer
Look at your MapAnnotation's initWithTitle method.Woodborer
let us continue this discussion in chatWoodborer
@Idindu: declared the same, it is unused. Still crash is there.Ellanellard

© 2022 - 2024 — McMap. All rights reserved.