canShowCallout only on Some Annotations

Discussion in 'iOS Programming' started by newtoiphonesdk, Feb 8, 2012.

  1. newtoiphonesdk
    Expand Collapse
    macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    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. jnoxx
    Expand Collapse
    macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    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. newtoiphonesdk
    Expand Collapse
    thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #3
    Not sure. Here is how I plot the annotations
    Code:
     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
    Code:
    -(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
    Code:
    ann28.accessibilityHint = @"YES"; 
    and then in the annotationView adding
    Code:
    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