开发者

How to show the title on my Pin Annotation and make it clickable to perform some action?

In my MapView i have pin dropped on certain locations and now i want to display some title on these pin annotation and make it clickable so that on click i can push a开发者_StackOverflow中文版nother view. Please help !!!!


This is the code snippet:

Custom Annotation View using this method

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    if (annotation == mapView.userLocation) return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];
    if (pin == nil)
    {
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"asdf"] autorelease];
    }
    else
    {
        pin.annotation = annotation;
    }
    pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pin.pinColor = MKPinAnnotationColorRed;
    pin.animatesDrop = YES;
    [pin setEnabled:YES];
    [pin setCanShowCallout:YES];
    return pin;

}

Delegate method which get's called when you tap on the button

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

    //DetailPg=[[BookMarksDetail alloc]initWithNibName:@"BookMarksDetail" bundle:nil];
    //DetailPg.selectRest =[view.annotation title]; //In addition, to get the Title of the AnnotationView.
    //DetailPg.m=1;
    //[self.navigationController pushViewController:DetailPg animated:YES];
    //[DetailPg release];

}


The answers to this are all provided in Apples Docs I suggest you read them more closely. However to have a call out all you need to do is set the title property.

For buttons and such you need to use the MapView Delegate method:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

_pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

Apple suggests reusing annotations this is something you will need to take into account.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜