OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在不取消选择注释的情况下更新标注 View ? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 08:59
标题: ios - 如何在不取消选择注释的情况下更新标注 View ?

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

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

但是,这种方法会在我的应用中造成一些不必要的副作用。

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



Best Answer-推荐答案


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

通过明确通知 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4