MKAnnotationView不显示标注 [英] MKAnnotationView doesn't show callout

查看:423
本文介绍了MKAnnotationView不显示标注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个MKMapView显示一个带有标注气泡的图钉。

I'm trying to get an MKMapView to show a pin with a callout bubble. I get the pin to display, but I just cant figure out how to display the callout.

有我的代码:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
    if (annotation == mapView.userLocation) {
        return nil;
    }
    MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
    pinView.pinColor = MKPinAnnotationColorGreen;
    [pinView setCanShowCallout:YES];
    pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.animatesDrop = YES;
    [self performSelector:@selector(displayPinCallOutView) withObject:nil afterDelay:0.3];
    return pinView;
}


推荐答案

获取要在地图中添加注释后显示的标注,您必须在 didAddAnnotationViews 委托方法中执行:

If you're trying to get the callout to display as soon as the annotation is added to the map, you have to do it in the didAddAnnotationViews delegate method:

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    //Get reference to annotation you want to select...
    //You could search through mapView.annotations array
    //or keep ivar reference to it.
    id<MKAnnotation> annToSelect = ...

    [mapView selectAnnotation:annToSelect animated:YES];
}

删除 performSelector viewForAnnotation 方法。

这篇关于MKAnnotationView不显示标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆