添加附件视图按钮来的MKMapView叫出注解? [英] Adding an accessory view button to the MKMapView call out annotation?

查看:115
本文介绍了添加附件视图按钮来的MKMapView叫出注解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到本网站,我已经一直试图添加到我的电话了视图按钮(从图片)。

I've recently come across this website and I've been trying to add to my call out view a button (from a image).

在网站上例中的code工作得很好,但是当我试图在同一code添加到我的项目,我没有得到相同的结果。

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!

下面是我的code的注释:

Here is my code for annotating:

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

任何帮助将是AP preciated! :)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆