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;
使用 kAnnotationViewRightAccessoryWidth 和kAnnotationViewRightAccessoryHeight
都等于 32。
当我不再需要这些按钮时,我尝试(并且在大多数情况下设法)像这样摆脱它们:
selectedAnnotationView.rightCalloutAccessoryView = nil;
selectedAnnotationView.leftCalloutAccessoryView = nil;
在 iOS 中4、这会导致附属视图消失,一切都工作得很好。然而,在 iOS 3 中,这两个按钮仍然保留,即使它们不可点击,就好像它们没有完全从标注视图中删除一样。
另外,如果我单击任何其他注释视图,则会出现两个按钮。
有谁知道如何解决这个问题?
谢谢!
编辑:
这是发生的情况的图片:
I've got a problem with the accessory views in the MKAnnotationView
s, 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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之后拨打电话
make call after