イベントリスナーを追加したマップマーカーがあります。マーカーをクリックすると、NSLog outメッセージを表示できます...それでも、マップをクリックすると、同じように動作します。これが通常の動作かどうかわかりませんか?結局、私はポップアップビューコントローラーを表示させようとしていますが、これが機能するまで保留されています。
だから...私はこのように見えるannotationviewをサブクラス化しました
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
if(self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
self.image = [UIImage imageNamed:@"numberplate.png"];
self.frame = CGRectMake(0,0,133,40);
self.centerOffset = CGPointMake(76,0);
//self.selected = NO;
self.canShowCallout = NO;
}
return self;
}
次に、メインのView Controllerに、
- (MKAnnotationView *)mapView:(MKMapView *)lmapView viewForAnnotation:(id <MKAnnotation>)annotation {
VehicleViewInfo *eventView = (VehicleViewInfo *)[lmapView
dequeueReusableAnnotationViewWithIdentifier:
@"eventview"];
if(eventView == nil) {
eventView = [[[VehicleViewInfo alloc] initWithAnnotation:annotation
reuseIdentifier:@"eventview"]
autorelease];
}
[eventView addObserver:self
forKeyPath:@"selected"
options:NSKeyValueObservingOptionNew
context:GMAP_ANNOTATION_SELECTED];
eventView.annotation = annotation;
return eventView;
}
だから私のイベントリスナーでは、私は
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context{
NSString *action = (NSString*)context;
NSLog(@"action received: %@", context);
if([action isEqualToString:GMAP_ANNOTATION_SELECTED]){
NSLog(@"ooh you clicked the annotation!");
}
}
また、GMAP_ANNOTATION_SELECTEDを次のように設定します
NSString * const GMAP_MAP_SELECTED = @ "mapselected";
マーカーをクリックしたときに得られる出力は期待どおりです。しかし、マップ領域をクリックすると、同じ応答が返されます。(地図をクリックしたかのように)。
すべての注釈などをキャンセルするには、mkmapに何らかのリスナーを追加する必要がありますか?