1

我在使用时遇到了一些问题MKAnnotation,我想在 MapView 上添加一个注释,所以我创建了一个名为的类AdoptingAnAnnotation.h文件遵循 #import #import

@interface  AdoptingAnAnnotation: NSObject {
}

@synthesize latitude; 
@synthesize longitude;

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (NSString *) title;
- (NSString *) subtitle;
@end

和 .m 文件如下

#import "AdoptingAnAnnotation.h"

@implementation AdoptingAnAnnotation

@synthesize latitude;
@synthesize longitude;

- (id) initWithLatitude:(CLLocationDegrees) lat longitude:(CLLocationDegrees) lng {
    latitude = lat;
    longitude = lng;
    return self;
   }
- (CLLocationCoordinate2D) coordinate {
    CLLocationCoordinate2D coord = {self.latitude, self.longitude};
    return coord;
    }
- (NSString *) title {
    return @"217 2nd St";
    }
- (NSString *) subtitle {
    return @"San Francisco CA 94105";
    }
@end

获取错误消息,例如illegal interface qualifier Is my syntax error 或其他关于MKAnnotation?

4

2 回答 2

2

您的@synthesize语句属于类实现,而不是接口。这就是您收到“非法接口限定符”错误的原因。最后,你的类应该采用 MKAnnotation 协议。

于 2012-02-25T05:51:26.930 回答
0

您发布了您的 .h 两次...请编辑。您的 .h 中还有合成器,它们属于 .m。并确保你实现了那些 MKAnnotation 方法。

于 2012-02-25T05:52:47.520 回答