0

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を使用しており、ストーリーボード/自動参照カウントを使用していません

ありがとうサミット

4

1 に答える 1

0

coordinateプロパティを として定義したreadonlyため、設定できません。

に変更しreadwriteます。

titleまた、 、subtitle、および settableを持つ基本的な注釈オブジェクトが必要な場合は、独自のクラスを定義する代わりにcoordinate組み込みクラスを使用できます。MKPointAnnotation作成と初期化は同じです (クラス名を に置き換えるだけですMKPointAnnotation)。

于 2011-10-21T21:15:08.530 に答える