4

我对 MKMapView 有疑问。我添加这样的注释:

// 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];
}

因此,我尝试在添加后立即显示标注 bouble,而不是在点击注释引脚后。在模拟器中一切正常,在 iOS 4.3.2 的 iPhone 3GS 上也是如此。但是,标注不会在装有 iOS 4.1 的 iPhone 4 上显示(它们仅在点击 pin 后才会显示)。知道如何解决这个问题吗?

4

4 回答 4

1

我的猜测是您没有为注释类的 title 属性分配值。即使您可以设置canShowCalloutYES,除非您的标题中有内容,否则标注气泡不会显示。

于 2011-06-25T16:55:01.670 回答
0

尝试添加

placeAnnotation.canShowCallout = YES;

所以它看起来像:

// 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];
}

希望这可以帮助!威萨姆

于 2011-06-22T04:41:02.713 回答
0

您将需要实现以下方法:

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

你可以在这里找到文档

于 2012-07-04T07:58:07.767 回答
0

你在错误的时间调用它。在加载之前您无法选择它。

使用 MKMapView 的委托方法:

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

从该方法调用内部:

[yourMapView selectAnnotation: yourAnnotation animated: YES];
于 2012-07-16T22:02:00.957 回答