「認識されていないセレクタ」を使用してMkplaceMarkクラッシュアプリケーションを呼び出す

StackOverflow https://stackoverflow.com//questions/9647486

質問

私はMKMapviewを持っていますユーザーが選択したばかりの建物の場所を表すための単一のmkplacemarkを追加しています。ユーザーは一度に1つの建物しか選択できません。また、新しい建物を選択すると、プラクマークを新しい建物に移動したいだけです。最初の建物で選択して、それはうまく機能し、ピンを地図に置きます。私が新しい建物を選択したときにマーカーの位置を更新するために、PlaceMarkのsetCoordinateを試して電話をかけてください。

MyViewController.h私は:

@property (nonatomic, strong)MKPlacemark *selectedBuildingPlacemark;
.

MyViewController.m

@synthesize selectedBuildingPlacemark;

...

if (self.selectedBuildingPlacemark == nil) {
        self.selectedBuildingPlacemark = [[MKPlacemark alloc] initWithCoordinate:myCoord addressDictionary:nil];
        [mapView addAnnotation:self.selectedBuildingPlacemark];
    }
    else {
        [self.selectedBuildingPlacemark setCoordinate:myCoord];
    }
.

私はMkplacemarkがMKANNOTATIONに準拠し、したがって-[MKPlacemark setCoordinate:]: unrecognized selector sent to instanceを実装すると思いました。誰かが私の方法の誤りを見せてくれる?

役に立ちましたか?

解決

The documentation of MKAnnotation says:

Annotations that support dragging should implement this method to update the position of the annotation.

So the method setCoordinate: is optional and is only implemented by classes that support dragging. The documentation of MKPlacemark does not reference that method, so it is not implemented.

So you should create a new instance every time you select a new building.

他のヒント

If you don't specifically need to use an MKPlacemark (it doesn't look like it because you're passing nil for the addressDictionary), you could use the MKPointAnnotation class instead.

MKPointAnnotation implements MKAnnotation but adds a setCoordinate method.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top