4

I have a problem with MKMapView. I add annotations like that:

// set up new points
for(int i = 0; i < [_locations count]; i++) {
    PPlace * place = [_locations objectAtIndex:i];
    PlaceAnnotation * placeAnnotation = [[PlaceAnnotation alloc] initWithPlace:place];
    // if annotation is for currently selected place
    placeAnnotation.isCurrent = i == currentIndexPath.row;
    [self.mapView addAnnotation:placeAnnotation];
    if (placeAnnotation.isCurrent) {
        [self.mapView selectAnnotation:placeAnnotation animated:YES];
    }
    [placeAnnotation release];
}

So I try to display callout bouble immediately after added, not after annotation pin is tapped. Everything works fine in simulator, also on iPhone 3GS with iOS 4.3.2. However, the callouts do not show on iPhone 4 with iOS 4.1 (they show only after pin is tapped). Any idea how to solve this?

Marcin
  • 1,823
  • 3
  • 16
  • 18

4 Answers4

1

My guess is that you did not assign a value to the title property of your annotation class. Even though you may set canShowCallout to YES, the call out bubble will not show unless you have something in your title.

Vistor
  • 11
  • 1
  • I do assign title and subtitle. If I wouldn't, the callout would never appear, doesn't matter if on simulator or device. But it does appear for example on simulator, or on iPhone 3GS with iOS 4.3.2. – Marcin Jun 27 '11 at 10:00
0

You will need to implement the following method:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

You can find the documentation here

codingNinja
  • 371
  • 2
  • 18
0

You are calling it at the wrong time. You can't select it until after it has loaded.

Use the delegate method of the MKMapView:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views

And from inside of that method call:

[yourMapView selectAnnotation: yourAnnotation animated: YES];
brant
  • 369
  • 3
  • 8
0

try adding

placeAnnotation.canShowCallout = YES;

so it looks like:

// set up new points
for(int i = 0; i < [_locations count]; i++) {
    PPlace * place = [_locations objectAtIndex:i];
    PlaceAnnotation * placeAnnotation = [[PlaceAnnotation alloc] initWithPlace:place];
    // if annotation is for currently selected place
    placeAnnotation.isCurrent = i == currentIndexPath.row;
    [self.mapView addAnnotation:placeAnnotation];
    if (placeAnnotation.isCurrent) {
        [self.mapView selectAnnotation:placeAnnotation animated:YES];
        placeAnnotation.canShowCallout = YES;
    }
    [placeAnnotation release];
}

hope this helps! WeSaM

Joe Masilotti
  • 16,815
  • 6
  • 77
  • 87
nig
  • 39
  • 2
  • It won't work, because placeAnnotation is not derived from MKAnnotationView. It's just a subclass of NSObject. – Marcin Jun 24 '11 at 14:35
  • I have also class PlaceAnnotationView, which is a subclass of MKAnnotationView, created in - (MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id)annotation, and I do set there canShowCallout = YES. It doesn't work. – Marcin Jun 24 '11 at 14:37
  • 1
    Set title on `MKPointAnnotation` object, used to represent pin data structure. – Martin Berger Aug 03 '15 at 17:55