MKAnnotationView的标注没有正确刷新

时间:2011-08-16 14:36:50

标签: iphone mkmapview mkannotationview

我在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;

kAnnotationViewRightAccessoryWidthkAnnotationViewRightAccessoryHeight都等于32。

当我不再需要这些按钮时,我尝试(并且在大多数情况下管理)以这样的方式摆脱它们:

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

在iOS 4中,这会导致配件视图消失,一切都运行良好。但是,在iOS 3中,两个按钮保持不变,即使它们不可点击,就好像它们没有从标注视图中完全删除。

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

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

谢谢!

编辑:

以下是发生的事情的图片:

enter image description here

1 个答案:

答案 0 :(得分:0)

之后拨打电话
 selectedAnnotationView.rightCalloutAccessoryView = nil;
 selectedAnnotationView.leftCalloutAccessoryView = nil;


[selectedAnnotationView setNeedsDisplay];
相关问题