Iphone 我在大头针上加了一个观察者。有一个问题:有时我会得到双重调用observeValueForKeyPath
我在大头针上加了一个观察者。有一个问题:当我点击一个pin时,有时我会得到双重调用observeValueForKeyPath。我需要做什么Iphone 我在大头针上加了一个观察者。有一个问题:有时我会得到双重调用observeValueForKeyPath,iphone,observer-pattern,mkannotation,mkannotationview,Iphone,Observer Pattern,Mkannotation,Mkannotationview,我在大头针上加了一个观察者。有一个问题:当我点击一个pin时,有时我会得到双重调用observeValueForKeyPath。我需要做什么 annotationView.enabled = YES; annotationView.animatesDrop = YES; annotationView.pinColor = MKPinAnnotationColorRed, annotationView.canShowCallout = YES; - (void)observeValueForKe
annotationView.enabled = YES;
annotationView.animatesDrop = YES;
annotationView.pinColor = MKPinAnnotationColorRed,
annotationView.canShowCallout = YES;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSString *action = (NSString*)context;
if([action isEqualToString:@"ANSELECTED"])
{
BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
MKAnnotationView *annotationView = (MKAnnotationView *)object;
if ( [annotationView.annotation isKindOfClass:[RestaurantLocation class]] )
{
RestaurantLocation *annot = (RestaurantLocation *)annotationView.annotation;
if (annotationAppeared)
{do something}}
}
您正在观察哪个关键路径?为什么不使用didSelectAnnotationView委托方法?