UICRouteAnnotation *startAnnotation = [[UICRouteAnnotation alloc] initWithCoordinate [[routePoints objectAtIndex:0] coordinate]
title:@"Origin"
subtitle:@"Subtitle Here"
annotationType:UICRouteAnnotationTypeStart];
我正在尝试为此注释添加一个副标题,但是对UICRouteAnnotation没有多少经验,并且无法找到很多文档。通过例外添加“副标题:”。
我错过了什么?为什么字幕在这样做时不起作用?
答案 0 :(得分:1)
我没有意识到需要修改UICRouteAnnotation以接受字幕。这是我更新的UICRouteAnnotation的h和m文件。进行以下更改修复了我的问题,因此我在问题中发布的代码按预期工作。
感谢安娜指出我正确的方向。
.h文件
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
typedef enum UICRouteAnnotationType {
UICRouteAnnotationTypeStart,
UICRouteAnnotationTypeEnd,
UICRouteAnnotationTypeWayPoint,
} UICRouteAnnotationType;
@interface UICRouteAnnotation : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
UICRouteAnnotationType annotationType;
}
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;
@property (nonatomic) UICRouteAnnotationType annotationType;
- (id)initWithCoordinate:(CLLocationCoordinate2D)coord
title:(NSString *)aTitle
subtitle:(NSString *)aSubTitle
annotationType:(UICRouteAnnotationType)type;
@end
.m文件
#import "UICRouteAnnotation.h"
@implementation UICRouteAnnotation
@synthesize coordinate;
@synthesize title;
@synthesize subtitle;
@synthesize annotationType;
- (id)initWithCoordinate:(CLLocationCoordinate2D)coord
title:(NSString *)aTitle
subtitle:(NSString *)aSubTitle
annotationType:(UICRouteAnnotationType)type {
self = [super init];
if (self != nil) {
coordinate = coord;
title = [aTitle retain];
subtitle = [aSubTitle retain];
annotationType = type;
}
return self;
}
- (void)dealloc {
[title release];
[subtitle release];
[super dealloc];
}
@end