0

私はこれが初めてで、壁に頭をぶつけているので、あなたが提供できる助けがあれば幸いです。

私のアプリは、MKAnnotations に変換する一連の座標とタイトルをダウンロードしています。MKAnnotation プロトコルは問題なく実装できましたが、コードは次のとおりです。

Annotator.h:

#import <Foundation/Foundation.h>
#import "MapKit/Mapkit.h"

@interface Annotator : NSObject <MKAnnotation>

+ (Annotator *) createAnnotator:(CLLocationCoordinate2D *)coordinate
                      withTitle:(NSString *)title
                    andSubtitle:(NSString *)subtitle;

@property (nonatomic, strong) NSString *myTitle;
@property (nonatomic, strong) NSString *mySubtitle;
@property (nonatomic) CLLocationCoordinate2D *coordinate;

@end

これまでのところかなり退屈です。Annotator.m は次のとおりです。

#import "Annotator.h"

@implementation Annotator

@synthesize myTitle = _myTitle;
@synthesize mySubtitle = _mySubtitle;
@synthesize coordinate = _coordinate;

+ (Annotator *)createAnnotator:(CLLocationCoordinate2D *)coordinate
                     withTitle:(NSString *)title
                   andSubtitle:(NSString *)subtitle
{
    Annotator *annotation = [[Annotator alloc] init];
    annotation.myTitle = title;
    annotation.mySubtitle = subtitle;
    annotation.coordinate = coordinate;
    return annotation;
}

- (NSString *)title
{
    return self.myTitle;
}

- (NSString *)subtitle
{
    return self.mySubtitle;
}

@end

現在、他のほとんどのコードは中央のビュー コントローラーにあるので、HTTP 要求がデータと共に返されるとすぐに、それを反復処理して MKAnnotation オブジェクトを作成し、それぞれに対して次のことを行います。

[self.territoryMap addAnnotation:locationPin];

...ここで、self.territoryMap は、ストーリーボードにドラッグした MKMapView へのアウトレットであり、locationPin は、上記の Annotator 実装で作成した MKAnnotation オブジェクトです。

私が調べたソリューションの中には、MKMapViewDelegate メソッドが配置されているものもありますが、デフォルトの動作を探しているだけなので、必要ではないように思えます。ユーザーの場所のピンの色を変更できるデリゲートを見つけましたが、それは私が心配していることではありません。

私がしなければならないことは他にありますか?よくわかりません!あなたが提供できるどんな助けにも感謝します!

4

1 に答える 1

0

MapViews デリゲートを設定する必要があります。その後、正常に動作するはずです。

または、これを調べてください: http://maybelost.com/2011/01/a-basic-mapview-and-annotation-tutorial/ あなたがやろうとしていることはかなり似ています!

于 2012-08-30T08:32:35.427 に答える