MKMapView に MKAnnotations を配置しようとしています。利用可能なさまざまなチュートリアルで提案されている手順に従っています。次のように、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
PlaceMark.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];
}
誰かが私が間違っていることを教えてもらえますか? ところで、私はiOS sdk5.0でXcode4.2を使用しており、ストーリーボード/自動参照カウントを使用していません
ありがとうサミット