2010-01-14 10 views
5

J'ai un MKMapView mis en œuvre avec ces lignes de code source (mon emplacement est une balle bleue, les autres ses sont des broches violettes):MKMapView -> afficher un bouton pour mon emplacement

- (MKAnnotationView *)mapView:(MKMapView *)mapViewLocal viewForAnnotation:(id <MKAnnotation>)annotation { 
    if (annotation == mapViewLocal.userLocation) { 
     mapViewLocal.userLocation.title = @"Test"; 
     [mapViewLocal setRegion:MKCoordinateRegionMakeWithDistance(mapViewLocal.userLocation.coordinate, 1000, 1000) animated:YES]; 
     return nil; 
    } 

    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapViewLocal dequeueReusableAnnotationViewWithIdentifier:@"Pin"]; 
     if(pinView == nil) { 
      pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease]; 
      pinView.pinColor = MKPinAnnotationColorPurple; 
      pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
      pinView.animatesDrop = NO; 
      pinView.canShowCallout = YES; 
     } else { 
      pinView.annotation = annotation; 
     } 
     return pinView; 
    } 

Les broches violettes ont un bouton de divulgation de détail, mais mon annotation n'en a pas. Comment puis-je définir un tel bouton?

Et c'est la méthode où je peux faire un bouton est somethin pressd:

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 

Comment pourrais-je faire la différence entre ma position et tous les autres son, parce que je besoin d'un traitement différent. Y a-t-il un autre délégué ou dois-je faire une sorte de clause if?

Répondre

4

dans votre didUpdateToLocation quelque chose d'écrire comme

AddressAnnotation *myAnnotation = [[AddressAnnotation alloc] initWithCoordinate:currentLocation]; 
       myAnnotation.title = @"You are here"; 
       [self.mapView addAnnotation:myAnnotation]; 

Et puis

Something Like

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
      // try to dequeue an existing pin view first 
     static NSString* annotationIdentifier = @"annotationIdentifier"; 

     NSString *titlestr = annotation.title; 

     MKPinAnnotationView* pinView = (MKPinAnnotationView *) 
     [mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier]; 
    MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:nil] autorelease]; 
     if (!pinView) 
     { 
      // if an existing pin view was not available, create one 
      // MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
                //initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease]; 
      if([titlestr isEqualToString:@"You are here"]) 
      { 
       customPinView.pinColor = MKPinAnnotationColorGreen; 
       NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;"); 
      } 
      else{ 
       customPinView.pinColor = MKPinAnnotationColorPurple; 
       customPinView.selected = TRUE; 
       NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;"); 
       UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
       [rightButton addTarget:self 
           action:@selector(ShowStoreDetail:) 
         forControlEvents:UIControlEventTouchUpInside]; 
       customPinView.rightCalloutAccessoryView = rightButton; 
      } 
      customPinView.animatesDrop = YES; 
      customPinView.canShowCallout = YES; 

      return customPinView; 
     } 
     else 
     { 
      pinView.annotation = annotation; 



      if([titlestr isEqualToString:@"You are here"]) 
      { 
       customPinView.pinColor = MKPinAnnotationColorPurple; 
       NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;"); 
      } 
      else{ 
       customPinView.pinColor = MKPinAnnotationColorPurple; 
       customPinView.selected = TRUE; 
       NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;"); 
       UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
       [rightButton addTarget:self 
           action:@selector(ShowStoreDetail:) 
         forControlEvents:UIControlEventTouchUpInside]; 
       customPinView.rightCalloutAccessoryView = rightButton; 
      } 


     } 
     return pinView; 

    return nil; 
}