gpt4 book ai didi

iphone - MKAnnotationView viewForAnnotation 从未调用过

转载 作者:可可西里 更新时间:2023-11-01 03:26:32 26 4
gpt4 key购买 nike

在我花了 2 天时间搜索错误后,我不得不在这里寻求帮助。我有 MapViewController 并在 map 上放置了一些图钉。我从苹果代码示例的 MapCallouts 和 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]];
}

我不知道哪里出了问题。谁能给我提示缺少什么?我必须承认我对委托(delegate)模式没有任何经验。

最佳答案

确保设置了 map View 的 delegate 属性。

如果 map 是在 IB 中创建的,请右键单击它并将其委托(delegate)导出连接到文件所有者。

如果 map 是在代码中创建的,请在创建 map View 后设置委托(delegate):

mapView.delegate = self;

关于iphone - MKAnnotationView viewForAnnotation 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6412504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com