我有一些問題,當使用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