OGeek|极客世界-中国程序员成长平台

标题: ios - 将披露指示器添加到 map 引脚 iOS 5 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:05
标题: ios - 将披露指示器添加到 map 引脚 iOS 5

我似乎无法在我的 map 注释中添加披露按钮。

我也为我的 View Controller 实现了 MKMapViewDelegate。我错过了什么?

- (MKAnnotationView *)mapViewMKMapView *)map viewForAnnotationid <MKAnnotation>)annotation
{
    MKPinAnnotationView *mapPin = nil;
    if(annotation != map.userLocation) 
    {
        static NSString *defaultPinID = @"defaultPin";
        mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if (mapPin == nil )
            mapPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        mapPin.canShowCallout = YES;
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        mapPin.rightCalloutAccessoryView = infoButton;

    }
    return mapPin;
}



Best Answer-推荐答案


该代码应该可以工作,但请检查以下内容:

同样,不相关,但是,当 dequeue 返回注解 View 时,您应该将其 annotation 属性更新为当前注解(它之前可能已用于另一个注解)。此外,除非您使用 ARC,否则您还应该 autorelease View 。

- (MKAnnotationView *)mapViewMKMapView *)map viewForAnnotationid <MKAnnotation>)annotation
{
    MKPinAnnotationView *mapPin = nil;
    if(annotation != map.userLocation) 
    {
        static NSString *defaultPinID = @"defaultPin";
        mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if (mapPin == nil )
        {
            mapPin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                         reuseIdentifier:defaultPinID] autorelease];
            mapPin.canShowCallout = YES;
            UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            mapPin.rightCalloutAccessoryView = infoButton;
        }
        else
            mapPin.annotation = annotation;

    }
    return mapPin;
}

关于ios - 将披露指示器添加到 map 引脚 iOS 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8330638/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4