1

我有一些问题,当使用MKAnnotation, 我想在一个MapView 所以我创建了一个名为AdoptingAnAnnotation类添加注释, 的.h文件遵循 #进口 #进口如何使用MKAnnotation

@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 是我的语法错误还是其他有关MKAnnotation的错误?

回答

2

您的@synthesize语句属于类实现,而不是在接口中。这就是为什么你得到“非法接口限定符”错误。最后,你的班级应该采用MKAnnotation协议。

+0

但是当我从.h文件中删除@synthesize时,我收到了其他错误消息,如http://commondatastorage.googleapis.com/haibo/temp/Scr​​een%20Shot%202012-02-25%20at%202.08。 54%20 PM.png这意味着我应该声明一些东西 – timger 2012-02-25 06:11:43

+0

如果你要@synthesize'lattitude'和'longitude',你需要对@interface中的属性声明@property声明。同样,既然你已经有了一个@comperty的'coordinate'声明,你也应该为这个属性指定一个@synthesize指令,或者你应该自己提供这个访问器。 – Caleb 2012-02-25 06:16:56

0

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

+0

感谢您的提醒 – timger 2012-02-25 06:15:02