iphone - MKMapView callout doesn't show on iPhone 4 with iOS 4.1
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?
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.
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
You will need to implement the following method:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
You can find the documentation here
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];
精彩评论