MKMap
一連の がありMKAnnotations
ますが、すべて赤で問題ありません。IBで「ユーザーの場所を表示」を選択しMKAnnotation
、赤から青に変更するには、viewForAnnotation
メソッドにコードがあります:
if (annotation == theMap.userLocation)
return nil;
すべて問題なく、アプリは正常に動作しますが、ユーザーが誤って青いユーザー位置ドットをタップすると、次のクラッシュが発生します。
2012-02-01 20:43:47.527 AusReefNSW[27178:11603] -[MKUserLocationView setPinColor:]: unrecognized selector sent to instance 0x79b0720
2012-02-01 20:43:47.528 AusReefNSW[27178:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocationView setPinColor:]: unrecognized selector sent to instance 0x79b0720'
*** First throw call stack:
上記のコードを削除すると、すべて正常に動作しますが、ピンは赤です。私は青いアイコンを持っていることを好みますが、まだクラッシュの理由を発見していません. どんなアイデアでも大歓迎です。ありがとう。
解決しました!Marvin に感謝します。誰かが役に立つと思った場合に備えて、コードをここに示します。簡単に言うと、まず MKAnnotation が MyAnnotation クラスのものか、MKUserLocation クラスのものかを確認する必要がありました。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view
{
theAnnotationSelected = [[mapView selectedAnnotations] objectAtIndex:0];
if ([theAnnotationSelected isKindOfClass:[MyAnnotation class]] )
{
view.pinColor = MKPinAnnotationColorGreen;
}
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKPinAnnotationView *)view
{
if ([theAnnotationSelected isKindOfClass:[MyAnnotation class]] )
{
view.pinColor = MKPinAnnotationColorRed;
}