我有一些问题,当使用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
的错误?
但是当我从.h文件中删除@synthesize时,我收到了其他错误消息,如http://commondatastorage.googleapis.com/haibo/temp/Screen%20Shot%202012-02-25%20at%202.08。 54%20 PM.png这意味着我应该声明一些东西 – timger 2012-02-25 06:11:43
如果你要@synthesize'lattitude'和'longitude',你需要对@interface中的属性声明@property声明。同样,既然你已经有了一个@comperty的'coordinate'声明,你也应该为这个属性指定一个@synthesize指令,或者你应该自己提供这个访问器。 – Caleb 2012-02-25 06:16:56