2011-10-21 22 views
0

MKAnnotationsをMKMapViewに配置しようとしています。私は様々な利用可能なチュートリアルで提案されている手順に従っています。私は以下のようにNSobjectクラスからPlaceMark.h/.mファイルを作成しました。 PlaceMark.hMKAnnotationクラスの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

MKMapViewを保持している私のViewControllerで
#import "PlaceMark.h" 

@implementation PlaceMark 
@synthesize coordinate,title; 

-(void)dealloc 
{ 
    [title release]; 
    [super dealloc]; 
} 

@end 

、の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]; 
} 

誰もが私がやっているものを私に教えてくださいすることができ違う?ところで私は、iOSのsdk5.0とXcode4.2を使用していますし、 は、あなたはとてもあなたがそれを設定することはできませんreadonlyとしてcoordinateプロパティを定義した

おかげ スミット

答えて

0

をカウント絵コンテ/自動参照を使用していません。

readwriteに変更してください。あなただけtitlesubtitle、および設定可能なcoordinateとの基本的な注釈オブジェクトが必要な場合は

また、あなたはビルトインMKPointAnnotationクラスの代わりに、独自のクラスを定義を使用することができます。作成と初期化は同じです(クラス名をMKPointAnnotationに置き換えてください)。

+0

私はそれをしましたが、それでも私は同じエラーを与えていました。 – slonkar

+0

エラーは何ですか? – Anna

+0

それは私に同じエラーを示しました。その後、私はすべてを削除し、再び始まりました。 – slonkar

関連する問題