【问题标题】:Adding an accessory view button to the MKMapView call out annotation?向 MKMapView 调出注释添加附件视图按钮?
【发布时间】:2010-11-28 19:37:30
【问题描述】:

我最近遇到了this website,我一直在尝试向我的调用视图添加一个按钮(来自图像)。

网站示例上的代码运行良好,但是当我尝试将相同的代码添加到我的项目中时,我没有得到相同的结果。

显然我错过了一些东西,但我似乎无法解决这个问题!

这是我的注释代码:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    annView.pinColor = MKPinAnnotationColorGreen;

    UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeCustom];
    advertButton.frame = CGRectMake(0, 0, 23, 23);
    advertButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    advertButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    [advertButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal];
    [advertButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];

    annView.rightCalloutAccessoryView = advertButton;

    annView.animatesDrop=TRUE;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}

任何帮助将不胜感激! :)

【问题讨论】:

  • 很遗憾,您提供的链接已失效

标签: iphone objective-c annotations mkmapview


【解决方案1】:

那家伙正在使用自定义图像来模仿细节披露。您实际上可以很容易地获得标准的详细信息披露:

[UIButton buttonWithType:UIButtonTypeDetailDisclosure];

【讨论】:

  • 啊,谢谢,按照他们的意思去做总是有用的:)
【解决方案2】:

而不是像你在这里那样设置目标:

[advertButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];

您可以使用默认委托:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

【讨论】:

    【解决方案3】:

    很抱歉回答我自己的问题,但这已通过将 MKMapView 的委托设置为 ViewController 来解决。唷,我花了一段时间才弄明白,这太简单了!!

    【讨论】:

      猜你喜欢
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多