向 MKMapView 标注添加附件视图按钮? [英] Adding an accessory view button to the MKMapView call out annotation?
问题描述
我最近访问了这个网站 我一直在尝试在我的呼出视图中添加一个按钮(来自图像).
I've recently come across this website and I've been trying to add to my call out view a button (from a image).
网站示例中的代码运行良好,但是当我尝试将相同的代码添加到我的项目时,却没有得到相同的结果.
The code on the websites example works just fine, but when I tried to add in the same code to my project I'm not getting the same results.
显然我遗漏了一些东西,但我似乎无法解决这个问题!
There is obviously something I've missed but I cannot seem to work this one out!
这是我的注释代码:
- (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;
}
任何帮助将不胜感激!:)
Any help would be appreciated! :)
推荐答案
很抱歉回答我自己的问题,但这已通过将 MKMapView 的委托设置为 ViewController 来解决.呼,我花了一段时间才弄明白,这太简单了!!
Sorry to answer my own question but this was solved by setting the delegate of the MKMapView to the ViewController. Phew, took me a while to figure that out and it's so simple!!
这篇关于向 MKMapView 标注添加附件视图按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!