.h
@
interface AdoptingAnAnnotation: NSObject <MKAnnotation> {} // 加上MKAnnotation 的protocol
@
property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@
property (nonatomic, readonly, copy) NSString *title;
@
property (nonatomic, readonly, copy) NSString *subtitle;
// title 和 subtitle按你之前的写也没啥事
@
end.m
@
synthesize coordinate; // @
synthesize 是跟 @
property 配合的 详细去看文档 Advanced Memory Management 貌似叫这个
@
synthesize title, subtitle;
- (id) initWithLatitude:(CLLocationDegrees) lat longitude:(CLLocationDegrees) lng {
self = [super init]
if (self) {
coordinate.latitude = lat;
coordinate.longitude = lng;
}
return self;
}
- (NSString *) title {
return @"217 2nd St";
}
- (NSString *) subtitle {
return @"San Francisco CA 94105";
}
@
end // 这样差不多了吧
新手就看文档 多参考文档中的sample project 多看看xxxxx Guide
另外先把objc的基本内容弄明白