2013-02-28 4 views
0

Je suis un développeur de noob to iphone et j'essaie d'ajouter un bouton personnalisé à une légende d'annotation. Je n'ai aucun problème à ajouter un bouton normal à rightCalloutAccessoryView, mais cela ne fonctionne pas pour le style personnalisé. Ma taille d'image est 32 x 32. Je veux aussi ajouter une broche de carte personnalisée suivant cette question stackoverflow here Toute aide est grandement appréciée.Comment ajouter un bouton/MapPin personnalisé à MKAnnotation?

MON CODE

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
// Define your reuse identifier. 
static NSString *identifier = @"MapPoint"; 

if ([annotation isKindOfClass:[MapPoint class]]) { 
    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 
    if (annotationView == nil) { 
     annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
    } else { 
     annotationView.annotation = annotation; 
    } 
    annotationView.enabled = YES; 
    annotationView.canShowCallout = YES; 
    annotationView.animatesDrop = YES; 
    annotationView.image = [UIImage imageNamed:@"myimage.png"]; 

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    //UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [rightButton setImage:[UIImage imageNamed:@"phony2.png"] forState:UIControlStateNormal]; 
    [rightButton addTarget:self 
        action:@selector(showDetails:) 
      forControlEvents:UIControlEventTouchUpInside]; 
    annotationView.rightCalloutAccessoryView = rightButton; 

    return annotationView; 
} 
return nil;  

}

Répondre

2
[rightButton addTarget:self 
       action:@selector(showDetails:) 

Retirez cette ligne et cadre ensemble de la touche

[rightButton setFrame:CGRectMake(0,0,32,32)]; 

et obtenir l'action du robinet de la méthode degate

Où vous obtenez la vue d'annotation.

J'espère que cela vous aidera.

+1

Merci de votre réponse. J'ai essayé votre suggestion mais je n'ai toujours pas de chance. –

+0

@B. Argent: Vous devez être plus précis que "ne pas avoir de chance". – Craig

Questions connexes