简体   繁体   中英

Displaying custom UIView in callout of pin(annotation) in map, using MapKit

In my application i want to display custom view(with buttons) in the case of user touches annotation on map(standard pin). i know that i can subclass MKAnnotationView and change the view of pin. but how can i change the look of Additional information view, that appears when user touches pin(by default it displays title and subtitle of MKAnnotation object). how can i do this?

Thanks.

- (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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM