我正在尝试将 MKAnnotations 放在 MKMapView 上。我正在遵循各种可用教程中建议的程序。我已经从 NSobject 类创建了 PlaceMark.h/.m 文件,如下所示。PlaceMark.h
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
@interface PlaceMark : NSObject<MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
}
@property (nonatomic,copy) NSString *title;
@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;
@end
地标.m
#import "PlaceMark.h"
@implementation PlaceMark
@synthesize coordinate,title;
-(void)dealloc
{
[title release];
[super dealloc];
}
@end
在我持有 MKMapView 的 viewController 中,在 viewDidload 我有以下代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MKCoordinateRegion region;
region.center.latitude=37.3305262;
region.center.longitude=-122.0290935;
region.span.latitudeDelta=0.01;
region.span.longitudeDelta=0.01;
[parkingMap setRegion:region animated:YES];
PlaceMark *ann=[[[PlaceMark alloc]init]autorelease]; // I have also tired it using explicitly defining method -(id)initwithTitle.... but it did not worked.
ann.title=@"Test";
ann.coordinate= region.center;
[parkingMap addAnnotation:ann];
}
谁能告诉我我做错了什么?顺便说一句,我正在使用 Xcode4.2 和 iOS sdk5.0 并且不使用情节提要/自动引用计数
谢谢苏米特