MKUserLocation 蓝色 userLocation MKAnnotation 如果不经意触摸会导致应用程序崩溃
我有一个 MKMap
和一系列 MKAnnotations
,所有这些都是红色的,这很好。我在 IB 中选择了“显示用户位置”,并将 MKAnnotation
从红色更改为蓝色,我的 viewForAnnotation
方法中有代码:
if (annotation == theMap.userLocation)
return nil;
一切都很好,应用程序可以正常工作很好,但如果用户无意中点击了蓝色的用户位置点,我会遇到以下崩溃:
2012-02-01 20:43:47.527 AusReefNSW[27178:11603] -[MKUserLocationView setPinColor:]: unrecognized selector sent to instance 0x79b0720
2012-02-01 20:43:47.528 AusReefNSW[27178:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocationView setPinColor:]: unrecognized selector sent to instance 0x79b0720'
*** First throw call stack:
如果我删除上面的代码,一切正常,但引脚是红色的。我更喜欢蓝色图标,但尚未发现崩溃的原因。任何想法将不胜感激。谢谢。
解决了!谢谢马文,这是代码,以防有人发现它有用。简而言之,我必须首先检查 MKAnnotation 是属于 MyAnnotation 类还是属于 MKUserLocation 类。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view
{
theAnnotationSelected = [[mapView selectedAnnotations] objectAtIndex:0];
if ([theAnnotationSelected isKindOfClass:[MyAnnotation class]] )
{
view.pinColor = MKPinAnnotationColorGreen;
}
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKPinAnnotationView *)view
{
if ([theAnnotationSelected isKindOfClass:[MyAnnotation class]] )
{
view.pinColor = MKPinAnnotationColorRed;
}
I have a MKMap
with a series of MKAnnotations
, all of which are red which is fine. I have selected "show user location" in IB and to change the MKAnnotation
from red to blue, I have the code in my viewForAnnotation
method:
if (annotation == theMap.userLocation)
return nil;
All is good and the app works fine, but if the user inadvertently taps the blue userlocation dot I get the following crash:
2012-02-01 20:43:47.527 AusReefNSW[27178:11603] -[MKUserLocationView setPinColor:]: unrecognized selector sent to instance 0x79b0720
2012-02-01 20:43:47.528 AusReefNSW[27178:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocationView setPinColor:]: unrecognized selector sent to instance 0x79b0720'
*** First throw call stack:
If I remove the above code, all works well but the pin is red. I perfer to have the blue icon but as yet have not discovered why the crash. Any ideas would be appreciated. Thanks.
SOLVED! Thanks Marvin and heres the code incase anyone finds it useful. In a nutshell, I had to first check to see if the MKAnnotation was of MyAnnotation Class or of MKUserLocation Class.
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view
{
theAnnotationSelected = [[mapView selectedAnnotations] objectAtIndex:0];
if ([theAnnotationSelected isKindOfClass:[MyAnnotation class]] )
{
view.pinColor = MKPinAnnotationColorGreen;
}
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKPinAnnotationView *)view
{
if ([theAnnotationSelected isKindOfClass:[MyAnnotation class]] )
{
view.pinColor = MKPinAnnotationColorRed;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于“当前用户位置”,请转到
MKMapView
属性并选择“在 XIB 中显示用户位置”。然后在你的控制器中实现MKMapViewDelegate..并在你的控制器中编写这个方法
,
使用这个你可以在用户位置上看到蓝点..
For Current User Location go to
MKMapView
property and make selection on Shows User Location in XIB.then Implement MKMapViewDelegate in your controller..and write this method in your controller
and this
Using this you can see blue dot on User Location..
您将需要检查注释的类,
然后执行以下操作。
You will want to check the class of the annotation in
Then do the following..
该解决方案在 iOS7 中可以抑制标注视图,但它不会阻止用户选择蓝点。 如何在地图视图中隐藏“当前位置”标注
我还没有找到一种方法来禁用当前位置点的选择。
与其说这是一种解决方法,不如说是一种“处理方法”,但我会放大地图,以便在点击时重点关注某些类型的注释。如果用户恰好位于某个注释的正上方,则缩放有助于在蓝点和我的注释之间留出一定的距离,从而更容易点击。
This solution works in iOS7 to suppress the callout view, but it does not stop the user from selecting the blue dot. How to suppress the "Current Location" callout in map view
I have yet to find a way to disable selection of the current location dot.
It isn't so much a workaround as a "way to deal with it", but I zoom the map in to focus on certain types of annotations when tapped. If the user happens to be located right on top of one, the zooming helps put some distance between the blue dot and my annotation, making it easier to tap.
我遇到了同样的问题,当用户点击 MKUserlocation“蓝点”时,应用程序会崩溃。我正在使用 Ching-Lan 'digdog' HUANG 的 DDAnnotation。我发现的修复是
I had the same issue such that when a user would tap the MKUserlocation "blue dot" the application would crash. I am using DDAnnotation by Ching-Lan 'digdog' HUANG. The fix I found was