iPhone - MKMapView 实例出现问题

发布于 2024-08-17 22:58:16 字数 292 浏览 4 评论 0原文

我遇到了 MKMapView 的问题,它作为全尺寸视图放置在 UITabBarController 的第一个位置。在显示视图之前,我向地图视图添加了几个注释。一切都很好。

当我更改选项卡(使地图视图不可见)并切换回带有地图视图的选项卡时,所有注释都消失了,看起来地图视图已重置为默认设置。

调试后我发现,当我切换回带有mapView的选项卡时,对mapView对象的引用指向与以前完全不同的地址。我认为,离开选项卡后,mapView 已被释放,但我完全不知道为什么?

预先感谢您的回复!

问候, 塞巴斯蒂安

I've got a problem with a MKMapView, which is placed as a full-sized view in a UITabBarController at first position. Before the view will be shown, I add several annotations to the mapView. Everything just works fine.

When I change the tab (so that the mapView is out of view) and switch back to the tab with the mapView, all annotations are gone and it looks like the mapView is reset to default settings.

After debugging I found out, that when I switch back to the tab with the mapView, the reference to the mapView object points to a completly different address than before. I assume, that the mapView has been deallocated after leaving the tab, but I completely don't know why?

Thanks in advance for your replies!

Greetings,
Sebastian

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

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

发布评论

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

评论(3

梦中的蝴蝶 2024-08-24 22:58:16

您将地图注释初始化代码放在哪里?在 -viewDidUnload 中,您可能将 mapView 设置为 nil,不是吗?如果是这样,请确保在 -viewDidLoad 中再次初始化视图时,您正在(重新)添加注释。

如果您有代码,那也会有帮助。

Where are you putting your map annotations initialization code? In -viewDidUnload, you're probably setting mapView to nil, no? If so, make sure when the view is initialized again in -viewDidLoad, you're (re)adding the annotations.

If you have code, that would also help.

烟沫凡尘 2024-08-24 22:58:16

因为它使用了太多内存,所以它正在被释放。
您应该在模型中保留有关视图的所有信息(注释、地图区域)
这样你就可以在 viewDidLoad 中预设它。

Because it is using too much memory, so it is being deallocated.

You should keep in a model all info about the view (annotations, map region)

So that in the viewDidLoad you could preset it.

长安忆 2024-08-24 22:58:16

我将注释的加载添加到 -viewDidLoad 中,并认为它现在可以正常工作了。感谢您的帮助!

I added the loading of the annotations to -viewDidLoad and think it works now as it should. Thanks for your help!

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