在MKAnnotationPinView中设置图像 [英] setting up Image in MKAnnotationPinView

查看:83
本文介绍了在MKAnnotationPinView中设置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在委托中包含以下代码:

I have the following code inside the delegate:

     - (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)anAnnotation 
{
    MKPinAnnotationView *pin = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier: @"RoutePin"];
    if (pin == nil)
    {
        if ([anAnnotation isKindOfClass:[RouteMapAnnotation class]])
        {
            RouteMapAnnotation *theAnnotation = (RouteMapAnnotation *)anAnnotation;
            if (theAnnotation.identifier == @"routePin")
            {
                //NSLog(@"TESTING PART III");
                MKPinAnnotationView *startAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:anAnnotation reuseIdentifier:@"RoutePin"];
                UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                startAnnotationPin.canShowCallout = YES;
                startAnnotationPin.animatesDrop = YES;

                startAnnotationPin.rightCalloutAccessoryView = rightButton;
                startAnnotationPin.pinColor = MKPinAnnotationColorRed;
                return startAnnotationPin;
            }
            else if (theAnnotation.identifier == @"finishPin")
            {
                NSLog(@"CREATING FINISH FLAG PRIOR");
                MKPinAnnotationView *finishAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:anAnnotation reuseIdentifier:@"FinishPin"];
                finishAnnotationPin.canShowCallout = NO;
                finishAnnotationPin.animatesDrop = YES;
                //finishAnnotationPin.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://cdn4.iconfinder.com/data/icons/formula1/f1_png/128/checkered_flag.png"]]];
                finishAnnotationPin.image = [UIImage imageNamed:@"flag_finish"];
                return finishAnnotationPin;

            }
        }
    }
    return nil;
}

但是,它没有在地图上显示图钉的图像.我想念什么?

However it's not showing the image for the pin on the map. What am I missing??

推荐答案

您应该使用MKAnnotationView而不是MKPinAnnotationView.

You should use MKAnnotationView instead of MKPinAnnotationView.

引脚注释用于引脚.

这篇关于在MKAnnotationPinView中设置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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