0

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...

iOSiOS
  • 214
  • 2
  • 5
  • 10

2 Answers2

1
-(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
Manu
  • 4,730
  • 2
  • 20
  • 45
  • : Hi Manohar, Now I have another problem.When the map is getting loaded for the second time,it doesnt display the pins.Please help me to find a solution.I have posted the question with code in the below link. http://stackoverflow.com/questions/16297158/annotated-pins-are-not-getting-loaded-during-reloading-of-map?noredirect=1#comment23330064_16297158 – iOSiOS Apr 30 '13 at 13:42
0

please try setting the frame for rightButton i.e

rightButton.frame = CGRectMAke (x,y,width,height);
Kasaname
  • 1,491
  • 11
  • 15