加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 从未调用过MKAnnotationView viewForAnnotation

发布时间:2020-12-14 19:57:08 所属栏目:百科 来源:网络整理
导读:在我花了2天的时间搜索这个bug后,我必须在这里寻求帮助.我有MapViewController并在地图上放置一些引脚.我已经从AppleCallouts和WeatherMap复制了苹果代码示例中的大部分代码. 无论如何,我似乎删除或遗漏了必要的部分.似乎MapViewController与以下代码之间没
在我花了2天的时间搜索这个bug后,我必须在这里寻求帮助.我有MapViewController并在地图上放置一些引脚.我已经从AppleCallouts和WeatherMap复制了苹果代码示例中的大部分代码.

无论如何,我似乎删除或遗漏了必要的部分.似乎MapViewController与以下代码之间没有任何关联

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"MKAnnotationView");
    return nil;
}

设置注释看起来像这样,它运作良好:

- (void)createPoi:(CLLocationCoordinate2D)theCoordinate
{
    NSLog(@"createPoi");

    RandomAnnotation *randomAnnotation = [[RandomAnnotation alloc] init];
    [randomAnnotation setTheCoordinate:theCoordinate];
    [randomAnnotation setTheTitle:@"bla"];
    [randomAnnotation setTheSubTitle:@"bla"];
    [self.mapAnnotations insertObject:randomAnnotation atIndex:kRandomAnnotationIndex];
    [randomAnnotation release];
    [self.mapView addAnnotation:[self.mapAnnotations objectAtIndex:kRandomAnnotationIndex]];
}

我无法弄清楚出了什么问题.任何人都可以给我一些提示吗?我不得不承认我对委托模式没有任何经验.

解决方法

确保已设置地图视图的委托属性.

如果在IB中创建了地图,请右键单击它并将其委托出口连接到文件所有者.

如果地图是在代码中创建的,请在创建地图视图后设置委托:

mapView.delegate = self;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读