0

PREAMBLE

I have implemented a map annotation using MKMapView and MapAnnotation. When tapped a title view appears as depicted in the following image.

map annotation title

I have used the following LOC to implement said map annotation:

// VENUE 1 PIN.

CLLocationCoordinate2D venue1Location = CLLocationCoordinate2DMake(-27.5, 153.5);

MapAnnotation *venue1Pin = [[MapAnnotation alloc] initWithTitle:@"1 ONE ST" Location:venue1Location];

VIEW FOR ANNOTATION DELEGATE METHOD:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MapAnnotation class]])
{
    MapAnnotation *venueLocationAnnotation = (MapAnnotation *)annotation;

    MKAnnotationView *venueLocationAnnotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"customAnnotation"];

    venueLocationAnnotationView.rightCalloutAccessoryView.hidden = YES;

    if (venueLocationAnnotationView == nil)

        venueLocationAnnotationView = venueLocationAnnotation.annotationView;

    else

        venueLocationAnnotationView.annotation = annotation;


        return venueLocationAnnotationView;

}
else
{
    return nil;
}

}

QUESTION

How do I remove the information button from the aforementioned map annotation title view ?

arman
  • 502
  • 3
  • 15
  • 1
    Please show your viewForAnnotation delegate method. –  Feb 19 '15 at 12:24
  • Please see above @Anna – arman Feb 19 '15 at 12:39
  • I have implemented the venueLocationAnnotationView.rightCalloutAccessoryView.hidden = YES; method in the delegate method and the custom annotation class. – arman Feb 19 '15 at 12:40
  • 1
    In the MapAnnotation class, looks like you have a method named annotationView. In that method, you must be setting rightCalloutAccessoryView. That cancels the effect (if any) of the "hidden = YES" line which comes _before_ the view is set. –  Feb 19 '15 at 12:50
  • Thank you for the advice. I added another " hidden = YES " to each of if / else ends of the delegate method and the button finally disappeared. Any idea how to centre the title text ? @Anna – arman Feb 19 '15 at 13:31
  • 1
    If you instead set it to nil, the title should center properly. Setting it to hidden still leaves space for the hidden view. But why not modify the annotationView method itself and not set the rCAV in the first place? –  Feb 19 '15 at 13:40

3 Answers3

2

You can use following statement:

You have to implement following delegate method for this:

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
         ...
         venue1Pin.rightCalloutAccessoryView = nil;
         ...
    }
Yuvrajsinh
  • 4,536
  • 1
  • 18
  • 32
  • I have implemented your suggestion. The " i " button is not disappearing. – arman Feb 19 '15 at 11:53
  • @arman have you implemented viewForAnnotation: delegate method? – Yuvrajsinh Feb 19 '15 at 12:08
  • Yes. I have implemented a MKMapView and set up all of the relevant LOC. The map annotation view is set up off a custom class w/ images etc. The images / titles change according to the various input I make. – arman Feb 19 '15 at 12:25
  • 1
    In the OP's code, venue1Pin is the annotation model object, not the view. The rightCalloutAccessoryView property is on the annotation view object, not the model. –  Feb 19 '15 at 12:46
1
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
annotationView.canShowCallout = YES;

annotationView.rightCalloutAccessoryView.hidden=YES;

return annotationView;
}
Mohd Prophet
  • 1,511
  • 10
  • 17
  • I have implemented your suggestion. The " i " button is not disappearing. – arman Feb 19 '15 at 11:52
  • 1
    By default, rightCalloutAccessoryView is nil when a new MKPinAnnotationView is created so setting the hidden property does nothing (because rCAV is nil). Only way the button shows is if OP is setting rCAV to something in which case they should just not set it to begin with. –  Feb 19 '15 at 12:43
1
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKPointAnnotation class]])
 {
  MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView   dequeueReusableAnnotationViewWithIdentifier:@"yourPinIdentifier"];
     if (!pinView)
     {
       pinView.rightCalloutAccessoryView.hidden=YES;
       pinView.animatesDrop = YES;
       pinView.canShowCallout = YES;
     }

    return pinView;
 }
}
  • I have implemented your suggestion. The " i " button is not disappearing. – arman Feb 19 '15 at 11:53
  • 1
    By default, rightCalloutAccessoryView is nil when a new MKPinAnnotationView is created so setting the hidden property does nothing (because rCAV is nil). Also, the code inside the `if (!pinView)` block will do nothing because that block is only executed if pinView is nil (and setting properties on a nil object have no effect). –  Feb 19 '15 at 12:45