将附件视图按钮添加到MKMapView调用注释?

问题描述:

我最近遇到了this website,我一直试图添加到我的电话中查看按钮(从图像)。将附件视图按钮添加到MKMapView调用注释?

网站示例上的代码工作得很好,但是当我试图将相同的代码添加到我的项目中时,我得不到相同的结果。

显然有一些我错过了,但我似乎无法工作这一个!

这里是我的代码为注解:

- (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; 
} 

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

+0

不幸的是,你提供的链接是死的 – 2016-10-14 20:59:09

对不起回答我自己的问题,但这是通过将MKMapView的委托设置到ViewController解决。 Phew,花了我一段时间来弄清楚这一点,它非常简单!

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

[UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
+0

啊谢谢,总是有用的做事情他们是如何意味着要做:) – 2009-10-19 11:38:47

而不是设置的目标是你一个人在这里:

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

你可以使用默认的委托:

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