Domanda

We are trying to implement MKMapView in iOS application.I got the mapView with the given locations and pins.When I tap on these pins I am getting the title and subtitle also.Now I want to include a detail Disclosure button in this view in which the title and subtitle are displayed.For that I used the below given code[MKPinannotation detail disclosure button - present new view is going inside the first method but it is not showing the detailDisclosureButton.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
    if (!pinView) {
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] autorelease];
        pinView.pinColor = MKPinAnnotationColorRed;
        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;

        UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView = rightButton;
    } else {
        pinView.annotation = annotation;
    }
    return pinView;
}


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

Now what can I do?Anyone please take a look and help me...

È stato utile?

Soluzione

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

    pinView = nil; 
    if(annotation != map.userLocation) 
    {
        NSString *defaultPinID =@"com.invasivecode.pin1";
        pinView = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
        UIButton *btnGo = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [btnGo addTarget:self action:@selector(goToLocation:)  forControlEvents:UIControlEventTouchUpInside];
        pinView.rightCalloutAccessoryView=btnGo;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
        pinView.draggable=NO;
    } 
    else {
        [map.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

Declare this in .h file

MKPinAnnotationView *pinView

Altri suggerimenti

please try setting the frame for rightButton i.e

rightButton.frame = CGRectMAke (x,y,width,height);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top