【问题标题】:MKAnnotationView's callout not refreshing properlyMKAnnotationView 的标注没有正确刷新
【发布时间】:2011-08-16 14:36:49
【问题描述】:

MKAnnotationViews 中的附件视图有问题,但仅在使用 iOS 3 SDK 时才会出现。具体是3.1.3版本。

我有一个MKAnnotationView 的子类,并以通常的方式创建它的实例:

SourceAnnotationView *annotationView = (SourceAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:kDefaultSourceAnnotationID];

if (annotationView == nil) {
    #if DEBUG
        NSLog(@"RecordViewController viewForAnnotation source %d",[sourceAnnotation.ioiIdent intValue]);
    #endif

    annotationView = [[[SourceAnnotationView alloc] initWithAnnotation:sourceAnnotation reuseIdentifier:kDefaultSourceAnnotationID] autorelease];
    annotationView.delegate = self;
}

稍后在代码中,我通过以下方式更改标注气泡的内容:

UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[deleteButton setImage:[UIImage imageNamed:kDeleteAudioButtonImageName] forState:UIControlStateNormal];
deleteButton.frame = CGRectMake(0, 0, kAnnotationViewLeftAccessoryWidth, kAnnotationViewLeftAccessoryHeight);
deleteButton.tag = kDeleteAudioButtonTag;
deleteButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
deleteButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[deleteButton addTarget:self action:@selector(calloutButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

selectedAnnotationView.leftCalloutAccessoryView = deleteButton;

UIButton *editAudioInfoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
editAudioInfoButton.frame = CGRectMake(0, 0, kAnnotationViewRightAccessoryWidth, kAnnotationViewRightAccessoryHeight);
editAudioInfoButton.tag = kEditInfoButtonTag;
editAudioInfoButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
editAudioInfoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[editAudioInfoButton addTarget:self action:@selector(calloutButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

selectedAnnotationView.rightCalloutAccessoryView = editAudioInfoButton;

kAnnotationViewRightAccessoryWidthkAnnotationViewRightAccessoryHeight 都等于 32。

当我不再需要这些按钮时,我会尝试(并且在大多数情况下会设法)像这样摆脱它们:

selectedAnnotationView.rightCalloutAccessoryView = nil;
selectedAnnotationView.leftCalloutAccessoryView = nil;

在 iOS 4 中,这会导致附件视图消失并且一切正常。然而,在 iOS 3 中,这两个按钮仍然存在,即使它们不可点击,就好像它们没有从标注的视图中完全移除一样。

此外,如果我单击任何其他注释视图,则会出现两个按钮。

有人知道怎么解决吗?

谢谢!

编辑:

这是发生了什么的图片:

【问题讨论】:

  • 您通过什么方法将标注附件视图设置为零?
  • @Anna Karenina 在点击导航栏右按钮时调用的方法
  • 所以将附件视图设置为按钮的代码在 viewForAnnotation 中,但将附件设置为 nil 的代码是在导航栏按钮方法中,对吧?
  • 那么只有SourceAnnotationView alloc+init在viewForAnnotation中?问题可能是附件的设置不在 viewForAnnotation 中,当视图被重用时,事情就会搞砸了。如何在导航按钮方法中访问 selectedAnnotationView?您的注释类中是否有可以在导航按钮方法中设置的属性,然后可以在 viewForAnnotation 中访问该属性以决定是否添加/删除附件?
  • 是的,我会尝试将附件设置/清除代码添加到 viewForAnnotation 以及在导航栏按钮方法中执行此操作并设置注释属性。

标签: iphone mkmapview mkannotationview


【解决方案1】:

之后拨打电话

 selectedAnnotationView.rightCalloutAccessoryView = nil;
 selectedAnnotationView.leftCalloutAccessoryView = nil;


[selectedAnnotationView setNeedsDisplay];

【讨论】:

  • 是否调用了 calloutButtonPressed
  • 不,它们是可见但不可触摸的。
猜你喜欢
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 2011-10-22
  • 2018-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多