I get this exception when I try to show a callout on my map annotation, even if the title is set.
This is the init method that I use in the 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 create 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 annotation 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 would like to do is use two different images for two map annotations. Any idea?
Thanks.
ios map mkannotationview mkannotation
Aleph72
source share