I can’t seem to be able to add a disclosure button to my map annotations.
I implemented the MKMapViewDelegate to my view controller as well. What am I missing?
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *mapPin = nil;
if(annotation != map.userLocation)
{
static NSString *defaultPinID = @"defaultPin";
mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (mapPin == nil )
mapPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
mapPin.canShowCallout = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
mapPin.rightCalloutAccessoryView = infoButton;
}
return mapPin;
}
That code should work but check the following:
delegateproperty set? Declaring that the view controller implements theMKMapViewDelegateprotocol does not actually tell the map view which object is implementing the delegate methods. In code, domap.delegate = self;or in IB connect thedelegateoutlet to File’s Owner.titleproperty set to non-blank? If thetitleis blank, no callout will show.Also, unrelated but, when the dequeue returns an annotation view, you should update its
annotationproperty to the current annotation (it might have been used for another annotation previously). Additionally, unless you’re using ARC, you should alsoautoreleasethe view.