canShowCallout only on Some Annotations

Discussion in 'iPhone/iPad Programming' started by newtoiphonesdk, Feb 8, 2012.

  1. macrumors 6502a

    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.
  2. macrumors 65816


    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.
  3. macrumors 6502a

    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 = @"";
            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?

Share This Page