Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

must implement title when canShowCallout is YES

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.

like image 530
Aleph72 Avatar asked Dec 24 '13 09:12

Aleph72


1 Answers

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

@property (nonatomic, copy) NSString *title;
like image 68
ldindu Avatar answered Oct 18 '22 19:10

ldindu