PDA

View Full Version : canShowCallout only on Some Annotations




newtoiphonesdk
Feb 8, 2012, 12:21 PM
How would you set a mapview to only show callout arrows on some of the annotations? Some of my annotations are for landmarks and do not need to display anything other than a title and subtitle.



jnoxx
Feb 9, 2012, 02:33 AM
Do they contain an object? For example, a custom made object, or a string you could make an custom init method with?
Then you can compare strings, to decide wether it should show call out or not.

newtoiphonesdk
Feb 9, 2012, 01:48 PM
Do they contain an object? For example, a custom made object, or a string you could make an custom init method with?
Then you can compare strings, to decide wether it should show call out or not.

Not sure. Here is how I plot the annotations
DisplayMap *ann28 = [[DisplayMap alloc] init];
ann28.title = @"Freeman Tower";
ann28.subtitle = @"";
ann28.coordinate = tower;

[mapView addAnnotation:ann28];
I add each annotation to a MutableArray called annotations, and then I have this method set up
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[detailButton setTitle:annotation.title forState:UIControlStateNormal];
NSInteger annotationValue = [self.annotations indexOfObject:annotation];

detailButton.tag = annotationValue;

[detailButton addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside];

pinView.rightCalloutAccessoryView = detailButton;
return pinView;


}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}

I tried adding ann28.accessibilityHint = @"YES"; and then in the annotationView adding
if (annotations.accessibilityHint == @"YES" {
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;}
else {
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = NO;
pinView.animatesDrop = YES;}
But that just made it to where none of the pins would display even a Title. Am I even close to being on the right track?