• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 将披露指示器添加到 map 引脚 iOS 5

[复制链接]
菜鸟教程小白 发表于 2022-12-13 10:05:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我似乎无法在我的 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-推荐答案


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

  • 是否设置了 map View 的 delegate 属性?声明 View Controller 实现 MKMapViewDelegate 协议(protocol)实际上并没有告诉 map View 哪个对象正在实现委托(delegate)方法。在代码中,执行 map.delegate = self; 或在 IB 中将 delegate 导出连接到文件的所有者。
  • 注释的 title 属性是否设置为非空白?如果 title 为空白,则不会显示标注。

同样,不相关,但是,当 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap