我试图在地图视图上放置多个图钉,但出现错误

2024-01-09

for (int i = 0; i < self.businessArray.count; i++) {
        Business *business = [self.businessArray objectAtIndex:i];
        MapAnnotation *mapAnnotation = [[MapAnnotation alloc] init]; 
        NSLog(@"%f %f", business.coordinate.latitude, business.coordinate.longitude);
        mapAnnotation.title = business.name;
        mapAnnotation.subtitle = business.address1;
        mapAnnotation.coordinate = business.coordinate;
        [bMapView addAnnotation:mapAnnotation];
        NSLog(@"ti %@", mapAnnotation.title);
        NSLog(@"sub %@", mapAnnotation.subtitle);
        NSLog(@"coo %f %f", mapAnnotation.coordinate.latitude, mapAnnotation.coordinate.longitude);
    }

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    MKPinAnnotationView *pinView;

    if (annotation != mapView.userLocation) {
        static NSString *defauleID = @"myLocation";
        //        pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:defauleID];
        if (pinView == nil) {
            pinView = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier:defauleID];
        }
        pinView.pinColor = MKPinAnnotationColorGreen;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;

        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        [rightButton addTarget:self 
                        action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
        pinView.rightCalloutAccessoryView = rightButton;
    }

    return pinView;
}

错误: MapAnnotation 类的实例 0x1cdd97b0 已被释放,而键值观察者仍向其注册。观察信息被泄露,甚至可能被错误地附加到其他物体上。在 NSKVODallocateBreak 上设置断点以在调试器中停止。以下是当前的观测信息: ( 上下文:0x0,属性:0x1cd97a30>


每次在循环内释放注释

    for (int i = 0; i < self.businessArray.count; i++) {
            Business *business = [self.businessArray objectAtIndex:i];
            MapAnnotation *mapAnnotation = [[MapAnnotation alloc] init]; 
            NSLog(@"%f %f", business.coordinate.latitude, business.coordinate.longitude);
            mapAnnotation.title = business.name;
            mapAnnotation.subtitle = business.address1;
            mapAnnotation.coordinate = business.coordinate;
            NSLog(@"ti %@", mapAnnotation.title);
            NSLog(@"sub %@", mapAnnotation.subtitle);
            NSLog(@"coo %f %f", mapAnnotation.coordinate.latitude, mapAnnotation.coordinate.longitude);
            [bMapView addAnnotation:mapAnnotation];
            [mapAnnotation release];
        }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我试图在地图视图上放置多个图钉,但出现错误 的相关文章

随机推荐

  • 相关查找字段外键在内联 Django 中不起作用

    我的 tabularinline 字段有问题 我有这样的模型 class Product models Model class Pemesanan models Model produks models ManyToManyField Pr
  • axios 在 componentDidMount 中获取数据后如何拍摄笑话快照?

    要测试的组件 class Carousel extends React Component state slides null componentDidMount gt axios get https s3 amazonaws com ra
  • 拖动数据点并提交值

    On page jqPlot http www jqplot com deploy dist examples customHighlighterCursorTrendline html有一个在 jqPlot 图表上拖动数据点的示例 我如何
  • Ajax v. 在 HTML 中包含数据

    我将 JavaScript 与 jQuery 结合使用 与 Django 后端对话 有一些 UI 需求需要 Ajax 因为在用户提供一些输入之前我们无法知道要发送哪些数据 然而 还有其他在模板时已知的数据 直接将该数据包含在模板中而不是使用
  • PHP ↔ Perl 接口或绑定

    您推荐哪种 PHP Perl 接口或绑定 我需要能够从 PHP 脚本运行位于 Perl 文件中的 Perl 函数并获取返回值 我已经找到了PECL perl 包 http pecl php net package perl但我不确定它的可靠
  • 64 位上 int 与 size_t

    将代码从 32 位移植到 64 位 很多地方都有 int len strlen pstr 这些现在都会生成警告 因为 strlen 返回 64 位的 size t 而 int 仍然是 32 位 所以我一直用它们替换 size t len s
  • 如何在提取文本之前识别可能损坏的 pdf 页面?

    TL DR 我的工作流程 下载PDF 使用将其拆分为页面pdftk https linux die net man 1 pdftk 使用提取每个页面的文本pdf转文本 https linux die net man 1 pdftotext
  • nginx 从rails 反向代理到wordpress

    我有一个 Ruby on Rails 应用程序和一个托管在不同 EC2 实例上的 Wordpress 博客 我正在尝试使 Wordpress 博客充当 Rails 应用程序的子文件夹 example com blog 而不是 blog ex
  • 在 Mac OS X 中链接动态库 (libjvm.dylib)(rpath 问题)

    我确实有一个需要链接的应用程序libjvm JDK 中的库需要进行 JNI 绑定 当我说出地点时libjvm dylib using L它成功编译和链接 但是 当我运行二进制文件时 我得到 dyld Library not loaded r
  • 如何在 Angular 中模拟 HTTP 请求?

    我检查了很多文章和答案 但似乎没有找到正确的方法来模拟HTTP Requests对于我的方法 我想测试我的frontend应用程序独立于backend 这是我拥有的方法类型 private getProfile this http get
  • 如何在每次启动时运行我自己的脚本

    我有一个问题 如何在 Ubuntu 中每次启动时运行自己的 bash 脚本 假设我有一个正在执行特定类型工作的脚本 现在我希望它在启动 Ubuntu 系统时自动运行 你应该学习如何使用暴发户 看this http upstart ubunt
  • 从 F# 中使用“params”调用泛型函数 (Observable.StartWith)

    Edit 请注意 正如 Daniel 和 latkin 在下面的回答和评论中指出的那样 这个问题涉及 F 中的一个错误 该错误似乎已于 2014 年初修复 我正在尝试为 Observable StartWith 编写一个咖喱包装器 我正在使
  • WordPress 中的 woocommerce 返回始终与产品类型一样简单

    我尝试获取分组产品的类型 但如果我使用 WC Product Factory woocommerce 返回空或始终 简单 当我使用时 the product new WC Product 2886 echo the product gt p
  • django send_mail() 函数需要几分钟

    我正在尝试在views py 文件中的函数中发送电子邮件 我已按照与此处相同的方式在我的设置文件中设置了电子邮件 Python Django Gmail SMTP 设置 https stackoverflow com questions 1
  • Java 1.5 命令行密码屏蔽

    All 我们的服务器正在运行 Java 1 5 我在尝试屏蔽来自命令行的用户输入时遇到了困难 我正在执行一个 jar 文件 java jar my jar 并通过 printlns 通过命令行提示符进行工作 我无法使用 Java 控制台 T
  • CDI 将服务注入 JPA 托管实体

    我确信这与这个问题 https stackoverflow com q 8512628 206466但是关于这个问题的OP有一些我不确定对DI是否有意义的场景 所以这就是我的理解 尝试将 JPA 实体与 CDI Bean 混合通常不是一个好
  • 图像 getWidth 和 getHeight 不适当地返回 -1

    为什么会这样 URL url MinecraftPlatformGame class getResource images diamondPick png image Toolkit getDefaultToolkit getImage u
  • Jquery 检查值是否为数字

    我想知道是否有人有一个快速而肮脏的 jquery 方法来检查一个值是否是数字 我正在考虑使用正则表达式类型方法来检查值 如果没有 则不要提交表单 我正在使用 jquery 验证 但我在加载 jquery 验证时遇到了问题 我只有一个值 我想
  • Laravel 创建具有两个时间戳列的表时出错

    我在 Laravel 6 6 中创建了一个具有以下定义的表 public function up Schema create quarters function Blueprint table table gt integer quarte
  • 我试图在地图视图上放置多个图钉,但出现错误

    for int i 0 i lt self businessArray count i Business business self businessArray objectAtIndex i MapAnnotation mapAnnota