MKAnnotationView 的标注未正确刷新

发布于 2024-11-30 03:17:54 字数 2563 浏览 1 评论 0原文

我在 MKAnnotationView 中的附件视图遇到问题,但仅在使用 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;

使用 kAnnotationViewRightAccessoryWidth 和kAnnotationViewRightAccessoryHeight 都等于 32。

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

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

在 iOS 中4、这会导致附属视图消失,一切都工作得很好。然而,在 iOS 3 中,这两个按钮仍然保留,即使它们不可点击,就好像它们没有完全从标注视图中删除一样。

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

有谁知道如何解决这个问题?

谢谢!

编辑:

这是发生的情况的图片:

在此处输入图像描述

I've got a problem with the accessory views in the MKAnnotationViews, but it only occurs when using the iOS 3 SDK. The 3.1.3 version specifically.

I have a subclass of MKAnnotationView and I create instances of it the usual way:

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;
}

Later on in the code, I change the content of the callout bubble by doing:

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;

with kAnnotationViewRightAccessoryWidth and kAnnotationViewRightAccessoryHeight being both equal to 32.

When I no longer need these buttons, I try (and in most cases manage) to get rid of them like this:

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

In iOS 4, this results in the accessory views dissapearing and everything working beautifully. However, in iOS 3 the two buttons stay, even though they're not clickable, as if they were not completely removed from the callout's view.

Also, if I click any other annotation view the two buttons appear.

Does anyone know how to solve this?

Thanks!

EDIT:

Here is a picture of what happens:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒岛晴空 2024-12-07 03:17:54

之后拨打电话

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


[selectedAnnotationView setNeedsDisplay];

make call after

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


[selectedAnnotationView setNeedsDisplay];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文