1

使用MKAnnotation、 私は はそう、私はAdoptingAnAnnotationという名前のクラスを作成するのMapViewに注釈を追加したいときに私はいくつかの問題を抱えている、 を使用する方法.hファイルが続く の#import の#importMKAnnotation

@interface AdoptingAnAnnotation: NSObject { 
} 

@synthesize latitude; 
@synthesize longitude; 

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 
- (NSString *) title; 
- (NSString *) subtitle; 
@end 

との.mファイルがillegal interface qualifierのようなエラーメッセージを取得

#import "AdoptingAnAnnotation.h" 

@implementation AdoptingAnAnnotation 

@synthesize latitude; 
@synthesize longitude; 

- (id) initWithLatitude:(CLLocationDegrees) lat longitude:(CLLocationDegrees) lng { 
    latitude = lat; 
    longitude = lng; 
    return self; 
    } 
- (CLLocationCoordinate2D) coordinate { 
    CLLocationCoordinate2D coord = {self.latitude, self.longitude}; 
    return coord; 
    } 
- (NSString *) title { 
    return @"217 2nd St"; 
    } 
- (NSString *) subtitle { 
    return @"San Francisco CA 94105"; 
    } 
@end 

に従っています文法エラーまたはMKAnnotationに関する他のエラーはありますか?

答えて

2

@synthesizeステートメントは、インターフェイスではなく、クラスの実装に属します。このため、「不正なインタフェース修飾子」エラーが発生します。最後に、クラスはMKAnnotationプロトコルを採用する必要があります。

+0

.hファイルから@synthesizeを削除すると、http://commondatastorage.googleapis.com/haibo/temp/Scr​​een%20Shot%202012-02-25%20at%202.08のような他のエラーメッセージが表示されます。 54%20 PM.pngこれは何かを宣言しなければならないことを意味します。 – timger

+0

'lattitude'と' longitude'を@synthesizeしようとするなら、あなたの@interfaceのものには@property宣言が必要です。同様に、 'coordinate'のための@property宣言を持っているので、そのプロパティのための@synthesizeディレクティブを持っているか、あなた自身がアクセサーを提供する必要があります。 – Caleb

0

.hを2回投稿しました。編集してください。また、あなたの.hにシンセサイザーがあり、それらは.mに属しています。これらのMKAnnotationメソッドを実装するようにしてください。

+0

思い出してくれてありがとう – timger

関連する問題