0
我試圖在MKMapView上添加MKAnnotations。我正在按照各種可用教程中提出的程序進行操作。我已經從NSobject Class創建了PlaceMark.h/.m文件,如下所示。 PlaceMark.h無法在MKAnnotation類中初始化CLLocationCoordinate2D iVar類
#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
PlaceMark.m
#import "PlaceMark.h"
@implementation PlaceMark
@synthesize coordinate,title;
-(void)dealloc
{
[title release];
[super dealloc];
}
@end
在我的viewController持有的MKMapView
,在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.
[email protected]"Test";
ann.coordinate= region.center;
[parkingMap addAnnotation:ann];
}
誰能告訴我我在做什麼錯誤?順便說一句,我使用Xcode4.2與iOS sdk5.0和 不使用故事板/自動引用計數
感謝 薩米特
我做到了,但仍然給了我同樣的錯誤。 – slonkar
什麼是錯誤? – Anna
它向我展示了同樣的錯誤。之後,我刪除了整個事情,並重新開始,這一次它的工作。 – slonkar