MapKit引脚标题没有显示

时间:2012-11-08 11:19:32

标签: xcode mapkit

位置正常,但标题没有出现,最奇怪。

location.latitude = (double) 51.501468;
location.longitude = (double) -0.141596;

// Add the annotation to our map view
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"ABC" andCoordinate:location];
[self.mapView addAnnotation:newAnnotation];
// [newAnnotation release];

MapViewAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapViewAnnotation : NSObject <MKAnnotation> {

NSString *title;
CLLocationCoordinate2D coordinate;

}

@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;

@end

和MapViewAnnotation.m

 #import "MapViewAnnotation.h"

 @implementation MapViewAnnotation

 @synthesize title, coordinate;

 - (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
title = ttl;
coordinate = c2d;
return self;
 }

 @end

[newAnnotation release]被重新安排以保持ARC的快乐:-) 有任何想法吗?

3 个答案:

答案 0 :(得分:1)

这就是诀窍:

[mapView selectAnnotation:newAnnotation animated:YES];

以前标题只会在您点击Pin时显示。

答案 1 :(得分:0)

您调用注释委托refer this linkmapkit-example-in-iphone

答案 2 :(得分:0)

该代码看起来很好(除了init方法的非标准实现)。

标题(标注)未显示的最可能原因是,在viewForAnnotation委托方法中,您未将canShowCallout设置为YES(默认为{{1} }})。

NO委托方法中,在您创建viewForAnnotation后,将MKAnnotationView设置为canShowCallout


无关标题/标注未显示,YES类中的init方法应按如下方式实现:

MapViewAnnotation
相关问题