2011-06-24 2 views
0

私は以前これについて質問があったと知っています。しかし、私はそれを解決することができないので、少し騒ぎと思う。MKAnnotation undeclared

これをしようとしたとき、私はそのエラーを取得しています:

MKAnnotation *annotation = [[MKAnnotation alloc] initWithCoordinate:coordenada title:@"HELLO!"]; 
[mapa addAnnotation:annotation]; 

私も次のような方法があります。

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation 
{ 
    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapa dequeueReusableAnnotationViewWithIdentifier: @"asdf"]; 
    if (pin == nil) 
    { 
     pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"asdf"] autorelease]; 
    } 
    else 
    { 
     pin.annotation = annotation; 
    } 
    pin.pinColor = MKPinAnnotationColorRed; 
    pin.animatesDrop = YES; 
    return pin; 
} 

とヘッダで#import < MapKit/MKAnnotation.h>をしましたが。

お願いします。

ありがとうございました!

答えて

5

MKAnnotationは、インスタンス化できるクラスではなく、プロトコルです。

あなたはMKAnnotationinitWithCoordinate:title:メソッドを実装する独自のクラスを定義していますか?持っていれば、そのクラス名を使用してヘッダファイルをインポートします。代わりに(4+のiOSに)あなたがあなた自身のアノテーションクラスを作成していない場合

は、作成する必要がありますか、事前に定義されたMKPointAnnotationクラスを使用することができます。

MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
annotation.coordinate = coordenada; 
annotation.title = @"HELLO!"; 
[mapa addAnnotation:annotation]; 
[annotation release]; 

あなたはよまた、次の操作を行う必要があります

  • プロジェクトにMapKitフレームワーク
  • は、ファイルの先頭に設定
  • #import <MapKit/MapKit.h>を追加追加delegateマップビューのプロパティ(またはIBのアウトレット)以外の場合viewForAnnotationは呼び出されません
関連する問題