私は XCode と iPhone の開発に非常に慣れていないので、この質問が単純すぎる場合はご容赦ください。しかし、私は地図を持っていて、注釈用に画像 (ピンではなく) を正常に追加しました。また、ユーザーが注釈の 1 つを選択すると、画像を変更できます。
次のメソッドを使用して MKAnnotationView から継承するクラスを作成しました:-
- (id)initWithAnnotation:
- (void)setAnnotation:
- (void)drawRect:
そして私は使用しています
- (void)touchesBegan
注釈がいつ選択されたかを知る。そして、私がやっていることを始めました:-
UIImage *i = [UIImage imageNamed:@"A.png"];
self.image = i;
イメージを変更します。しかし、私が本当に困惑しているのは、ユーザーが次の注釈を選択したときに、画像を元の画像に戻す方法です。私が試してみました:-
NSArray *selectedAnnotations = map.selectedAnnotations;
for(id annotationView in selectedAnnotations) {
[map deselectAnnotation:[annotationView annotation] animated:NO];
}
しかし、それはエラーです
そして私は試しました
for (MKAnnotationView *ann in map.selectedAnnotations){
if ([ann isMemberOfClass:[Place class]])
{
place = (Place *)ann;
NSLog(@"second = %@"@" %f"@" %f", place.title, place.longitude, place.latitude);
if (currentPlaceID == place.placeID) {
//UIImage *i = [UIImage imageNamed:@"A.png"];
//ann.image = i;
}
else {
UIImage *i = [UIImage imageNamed:@"pin.png"];
ann.image = i;
}
}
}
ann.image = i; に到達するまで、上記のコードは問題なく動作します。その後、エラーになります。私が得るエラーは次のとおりです:-
*** -[Place setImage:]: unrecognized selector sent to instance 0x4514370
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[Place setImage:]: unrecognized selector sent to instance 0x4514370'
はい、場所オブジェクトに画像がないことがわかります。そのため、問題が発生しています。しかし、場所オブジェクトに画像プロパティを作成すると、私がやろうとしている注釈画像がどのように変化しますか。
私はこれについて2日間ぐるぐる回っているので、アドバイスしてください!!!!
前もって感謝します シェリル