2011-01-17 13 views
3

In meiner Anwendung möchte ich benutzerdefinierte Ansicht (mit Schaltflächen) im Fall von Benutzer Berührungen Annotation auf der Karte anzeigen (Standard Pin). Ich weiß, dass ich MKAnnotationView Unterklasse und ändern Sie die Ansicht von Pin. Aber wie kann ich das Aussehen der Ansicht Zusätzliche Informationen ändern, die angezeigt wird, wenn der Benutzer die PIN berührt (standardmäßig werden Titel und Untertitel des MKAnnotation-Objekts angezeigt). wie kann ich das tun?Anzeigen benutzerdefinierter UIView in Callout von Pin (Annotation) in Map, mit MapKit

Danke.

Antwort

4
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id)annotation 
{ 
    MKPinAnnotationView *pinView = nil; 
    static NSString *defaultPinID = @"ReusedPin"; 
    pinView = (MKPinAnnotationView*)[mVdequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
    if (pinView == nil) 
     pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; 
    if (((PinAnnotationView*)annotation).tag == 0) 
    { 
     pinView.pinColor = MKPinAnnotationColorPurple; 
    } 
    else { 
     pinView.pinColor = MKPinAnnotationColorRed; 
    } 
    pinView.canShowCallout = YES; 
    pinView.animatesDrop = YES; 
    UIImageView *pinImageView = [[UIImageView alloc] initWithFrame:CGRectMake(-5, 0, 34, 34)]; 
    UIImage *pinImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png"]]; 
    pinImageView.image = pinImage; 
    [pinImage release]; 
    [pinView addSubview:pinImageView]; 
    [pinImageView release]; 
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    btn.tag = ((PinAnnotationView*)annotation).tag; 
    pinView.rightCalloutAccessoryView = btn; 
    return pinView; 
} 

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 
    if (control.tag !=0) { 
     ShowProviderDetailVC *viewControlle = [[ShowProviderDetailVC alloc]initWithNibName:@"ShowProviderDetailVC" bundle:nil]; 
     viewControlle.lastViewName = @"SearchView"; 
     for (NSMutableDictionary* dict in globalLocArray) { 
      if (control.tag ==[[dict valueForKey:@"ID"] intValue]) 
      { 
       viewControlle.providerInfoDict = dict; 
      } 
    } 
    [self.navigationController pushViewController:viewControlle animated:YES]; 
    [viewControlle release]; 
} 
+0

Oh, danke. Ich bin Neuling und ich wusste sogar nicht über RightCalloutAccessoryButton. –

Verwandte Themen