gpt4 book ai didi

ios - 将披露指示器添加到 map 图钉 iOS 5

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:17:50 25 4
gpt4 key购买 nike

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

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

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <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;
}

最佳答案

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

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

此外,无关但是,当出列返回一个注解 View 时,您应该将其 annotation 属性更新为当前注解(它可能之前已用于另一个注解)。此外,除非您使用的是 ARC,否则您还应该自动释放 View 。

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <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/

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