自定义地图注释 iPhone 中的警告
我正在 iPhone 中使用自定义地图注释类进行地图视图。每当我从导航栏堆栈中弹出地图视图时,我通常会在控制台中看到一些警告。
MapAnnotation 已被释放,而键值观察者仍向其注册。观察信息被泄露,甚至可能被错误地附加到其他物体上。在 NSKVODallocateBreak 上设置断点以在调试器中停止。这是当前的观察信息:
我没有在代码中使用 KVO,因此无法理解为什么我收到这些警告
I am using a custom map annotation class for map view in iPhone. Whenever I pop my map view from navigation bar stack I usually see some warnings in console.
MapAnnotation was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
I am not using KVO in my code hence not able to understand why I am receiving these warnings
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
纬度和经度具有不同的界限:纬度
传递超出这些界限的值将导致自定义类被释放,从而导致您收到错误。确保您传递了正确的纬度和经度值。
如果苹果为此传递一个边界错误而不是早期发布错误,那就太好了。这将为我节省大约 5 个小时的时间
Latitude and Longitude have differing bounds:
Passing a value outside of those bounds will cause the custom class to be deallocated and therefore giving you the error that you're receiving. Make sure that you are passing the correct values for both Latitude and Longitude.
It would be really nice if Apple passed a bounding error for this instead of an early release error. That would've saved me roughly 5 hours worth of time
我遇到了与您相同的错误:
正如此处所指出的,这是因为我向 MKMapView 添加了带有无效坐标的 MKAnnotation。
我的解决方案是创建一个函数来检查坐标是否有效。
Place+MKAnnotation.m
我创建了 Place 类的一个类别,
Place+MKAnnotation.m
仅在坐标有效的情况下在 ViewController 中添加注释。
I was getting the same error as you:
As pointed here it was caused because I was adding a MKAnnotation with an invalid coordinate to a MKMapView.
My solution was to create a function to check the coordinate valid.
Place+MKAnnotation.m
I created a category of my Place class and
Place+MKAnnotation.m
I only add the annotation in my ViewController if the coordinate is valid.
修好了。我在注释中使用了错误的纬度和经度对,我已经进行了相同的更改,现在一切似乎都很完美,警告也消失了。
Fixed it. I was using a wrong pair of latitude and longitude in annotations, I have changed the same and now everything seems to be perfect and warning has been disappeared as well.
在将注释添加到 MapView 之前是否会自动释放注释?
如果是这样,请尝试分配它,将其添加到 MapView,然后释放它。
Are you autoreleasing your annotation before adding it to the MapView?
If so, try just allocating it, add it to the MapView, then release it.