Sunday, 8 September 2013

Pin Callout Button Missing

Pin Callout Button Missing

I am using the following code to create my pin annotation callout, but my
Detail Disclosure Button and my custom image do not show up. It must have
something to do with if([annotation isKindOfClass:[CustomAnnotation
class]]) but I don't know what. What am I doing wrong here?
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
if ([annotation isKindOfClass:[CustomAnnotation class]])
{
MKPinAnnotationView *annotationView = (MKPinAnnotationView
*)[self.mapView
dequeueReusableAnnotationViewWithIdentifier:@"CustomAnnotation"];
if(annotationView == nil)
{
MKPinAnnotationView *customPinView = [[MKPinAnnotationView
alloc] initWithAnnotation:annotation
reuseIdentifier:@"CustomAnnotation"];
if([[customPinView.annotation title] isEqualToString:@"HQ"])
{
customPinView.pinColor = MKPinAnnotationColorPurple;
}
else
{
customPinView.pinColor = MKPinAnnotationColorRed;
}
customPinView.canShowCallout = YES;
customPinView.animatesDrop = YES;
UIButton *rightButton = [UIButton
buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:nil action:nil
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
return customPinView;
}
else
{
annotationView.annotation = annotation;
}
return annotationView;
}
return nil;
}

No comments:

Post a Comment