Luca
Luca

Reputation: 20959

The rightCalloutAccessory button is not shown

I try to manage annotations, and to display an info button on the right of the view when a PIN get selected, my relevant code is this:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {

    MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"greenPin"];

        if ([annotation isKindOfClass:[ManageAnnotations class]]) {
            static NSString* identifier = @"ManageAnnotations";   

            MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            if (newAnnotation==nil) {
                newAnnotation=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            }else {
                newAnnotation.annotation=annotation;
            }

            newAnnotation.pinColor = MKPinAnnotationColorGreen;
            newAnnotation.animatesDrop = YES;
            newAnnotation.canShowCallout = YES;
            newAnnotation.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeInfoLight];

            return newAnnotation;


        }else {
            newAnnotation.pinColor = MKPinAnnotationColorGreen;
            newAnnotation.animatesDrop = YES;
            newAnnotation.canShowCallout = YES;
            return newAnnotation;
        }

ManageAnnotations.m :

@implementation ManageAnnotations

@synthesize pinColor;
@synthesize storeName=_storeName;
@synthesize storeAdress=_storeAdress;
@synthesize coordinate=_coordinate;


-(id)initWithTitle:(NSString*)storeName adress:(NSString*)storeAdress coordinate:(CLLocationCoordinate2D)coordinate{

    if((self=[super init])){
        _storeName=[storeName copy];
        _storeAdress=[storeAdress copy];
        _coordinate=coordinate;

    }
    return self;

}
-(NSString*)title{

    return _storeName;
}
-(NSString*)subtitle{

    return _storeAdress;


}

ManageAnnotations.h

@interface ManageAnnotations : NSObject<MKAnnotation>{

    NSString *_storeName;
    NSString *_storeAdress;
    CLLocationCoordinate2D _coordinate;

}
//
@property(nonatomic,assign)MKPinAnnotationColor pinColor;
@property(nonatomic, readonly, copy)NSString *storeName;
@property(nonatomic, readonly, copy)NSString *storeAdress;
@property(nonatomic,readonly)CLLocationCoordinate2D coordinate;



//
-(id)initWithTitle:(NSString*)storeName adress:(NSString*)storeAdress coordinate:(CLLocationCoordinate2D)coordinate;
//

The PINS are shown correctly on the Map, but without the info button on the right of the view. Am i missing something?

Upvotes: 0

Views: 121

Answers (1)

Cyril Godefroy
Cyril Godefroy

Reputation: 1400

  1. Are you actually going into the condition? Set a breakpoint to check.
  2. Why create a MKPinAnnotationView at the beginning, before you know the type of annotation?
  3. You should dequeue your annotationView instead of alloc/initWithAnnotation:reuseIdentifier
  4. When you reuse your annotations, you should put everything that doesn't change (color, animation, etc) after the alloc init, and not reset them all the time. Otherwise you lose the interest of reusing.

Other than that your code seems fine, and comparing it to mine, I don't see anything obvious. Remark 1 is the most probable. I would set a breakpoint to see if I really go there, see if I can show a leftCalloutAccessoryView instead, use a different pinColor.

Upvotes: 1

Related Questions