到目前为止,我发现更新已经存在的标注气泡中的文本的唯一方法是取消选择其注释,然后再次选择它,如下所示:

id <MKAnnotation> annotation = self.selectedAnnotation; // Keep a reference
[self.mapView deselectAnnotation:self.selectedAnnotation animated:NO];
[self.mapView selectAnnotation:annotation animated:NO];

但是,这种方法在我的应用程序中引起了一些不必要的副作用。

有谁知道其他方法可以做到这一点?

最佳答案

安娜在对我的问题的评论中提供了一个完美的解决方案!

通过将文本更改明确通知MKMapView(它通过KVO侦听更改),我设法使标注得以更新,否则它就不会更新。这是工作代码:

[annotation willChangeValueForKey:@"subtitle"];
annotation.subTitle = @"New subtitle";
// subTitle is the property behind MKAnnotation's subtitle
[annotation didChangeValueForKey:@"subtitle"];

谢谢你安娜来救援=)

关于ios - 如何在不取消选择注释的情况下更新标注 View ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25640314/

10-14 23:42