For some odd reason the detail button somehow stopped appearing:
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mapView.userLocation)
{
MKPinAnnotationView *pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"sadasdasd"];
if ( pinAnnotation == nil ){
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"sadasdasd"] autorelease];
/* add detail button */
NSLog(@"Here");
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
}
return pinAnnotation;
}
Here is output.
Thanks in advance.
First problem is that
pinAnnotationis declared twice in that method.Once in the first line and second in the
if(annotation != mapView.userLocation)...block. Because of this, thereturnstatement returnsnilbecause the outer variable is never set (resulting in a defaultMKAnnotationViewcallout with no accessory).Change the second declaration to just an assignment.
Next problem is that you need to set
canShowCallouttoYESbecause the default isNOfor anMKPinAnnotationView. You can do this after setting the accessory view:The above should fix the accessory button not showing.
Unrelated, but you also need to set the view’s
annotationproperty when it is being re-used (in the case when it is not nil after the dequeue). So add anelseblock to theif (pinAnnotation == nil):