0
UICRouteAnnotation *startAnnotation = [[UICRouteAnnotation alloc] initWithCoordinate [[routePoints objectAtIndex:0] coordinate]
title:@"Origin"
subtitle:@"Subtitle Here"
annotationType:UICRouteAnnotationTypeStart];

我正在尝试为此注释添加副标题,但对 UICRouteAnnotation 没有太多经验,也无法找到太多关于它的文档。通过例外添加“字幕:”。

我错过了什么?为什么这样做时字幕不起作用?

4

1 回答 1

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
于 2012-08-30T17:29:46.657 回答