2011-05-12 2 views
1

Ceci est ma première question sur le débordement de pile et je suis également nouveau développement iOS. Je développe une application cartographique pour mon école. mon école a 25 bâtiments. J'ai 25 MKPinAnnotationViews sur ma carte.Comment implémenter plusieurs légendes dans MKPinAnnotationView

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
// if it's the user location, just return nil. 
if ([annotation isKindOfClass:[MKUserLocation class]]) 
    return nil; 

// handle our two custom annotations 
// 
if ([annotation isKindOfClass:[SchureAnnotation class]]) // for Harry Schure Hall 
{ 
    // try to dequeue an existing pin view first 
    static NSString* SchureAnnotationIdentifier = @"schureAnnotationIdentifier"; 
    MKPinAnnotationView* pinView = (MKPinAnnotationView *) 
    [mapView dequeueReusableAnnotationViewWithIdentifier:SchureAnnotationIdentifier]; 
    if (!pinView) 
    { 
     // if an existing pin view was not available, create one 
     MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
               initWithAnnotation:annotation reuseIdentifier:SchureAnnotationIdentifier] autorelease]; 
     customPinView.pinColor = MKPinAnnotationColorPurple; 
     customPinView.animatesDrop = YES; 
     customPinView.canShowCallout = YES; 

     // add a detail disclosure button to the callout which will open a new view controller page 
     // 
     // note: you can assign a specific call out accessory view, or as MKMapViewDelegate you can implement: 
     // - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control; 
     // 
     UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     [rightButton addTarget:self 
         action:@selector(showDetails:) 
       forControlEvents:UIControlEventTouchUpInside]; 
     customPinView.rightCalloutAccessoryView = rightButton; 

     return customPinView; 
    } 
    else 
    { 
     pinView.annotation = annotation; 
    } 
    return pinView; 
} 
else if ([annotation isKindOfClass:[SaltenAnnotation class]]) // for Salten Hall 
{ 
    // try to dequeue an existing pin view first 
    static NSString* SaltenAnnotationIdentifier = @"saltenAnnotationIdentifier"; 
    MKPinAnnotationView* pinView = (MKPinAnnotationView *) 
    [mapView dequeueReusableAnnotationViewWithIdentifier:SaltenAnnotationIdentifier]; 
    if (!pinView) 
    { 
     // if an existing pin view was not available, create one 
     MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
               initWithAnnotation:annotation reuseIdentifier:SaltenAnnotationIdentifier] autorelease]; 
.......... 

Je souhaite placer une légende différente pour afficher ses informations pour chaque broche. J'appelle la fonction showDetails: qui ressemble à ce

- (void)showDetails:(id)sender 
{ 
// the detail view does not want a toolbar so hide it 
[self.navigationController setToolbarHidden:YES animated:NO]; 

[self.navigationController pushViewController:detailViewController animated:YES]; 
} 

Inorder pour afficher les informations de chaque bâtiment, dois-je écrire 25 contrôleurs de vue? ou est-il de toute façon d'utiliser un contrôleur de vue? Si je clique sur le bouton droit de l'annotation, il doit montrer ses informations (image, texte). Si je clique sur une autre annotation, elle doit montrer ses informations en remplaçant l'ancienne.

Toute aide grandement appréciée. Merci, Pradeep.

Répondre

0

Ne pas utiliser le [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];

Modification

[rightButton addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];

Et puis:

Étape 1:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { [self performSegueWithIdentifier:@"TCServiceStationDetailFromMap" sender:view]; }

Étape 2:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 

{

si ([segue.identifier isEqualToString: @ "TCServiceStationDetailFromMap"]) {

MKAnnotationView *view = sender; 
    TSPlaceMark *detailPlaceMark = (TSPlaceMark *)view.annotation; 
    //... 
    //so that you can get the different MKAnnotationView 
} 

}

Questions connexes