Adding Disclosure Indicator to map pins iOS 5

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;
}

Answers


That code should work but check the following:

  • Is the map view's delegate property set? Declaring that the view controller implements the MKMapViewDelegate protocol does not actually tell the map view which object is implementing the delegate methods. In code, do map.delegate = self; or in IB connect the delegate outlet to File's Owner.
  • Is the annotation's title property set to non-blank? If the title is blank, no callout will show.

Also, unrelated but, when the dequeue returns an annotation view, you should update its annotation property to the current annotation (it might have been used for another annotation previously). Additionally, unless you're using ARC, you should also autorelease the view.

- (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] autorelease];
            mapPin.canShowCallout = YES;
            UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            mapPin.rightCalloutAccessoryView = infoButton;
        }
        else
            mapPin.annotation = annotation;

    }
    return mapPin;
}

Need Your Help

How to correctly use boost::timed_mutex and scoped_lock

c++ boost locking boost-thread boost-mutex

I am trying to use both timed_mutex with the scoped_lock. I have successfully used the scoped_lock before by following some examples but now I don't seem to find my way around neither I am able to

disable OnNavigatedTo when app resume

c# windows-phone-8 navigateuri

I wonder if its possible to disable the OnNavigatedTo event in windows phone application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.