【发布时间】:2015-11-10 05:09:08
【问题描述】:
我正在尝试通过触摸地图视图来添加注释,在我释放新闻后我收到此错误:
[MKPointAnnotation index] : 无法识别的选择器发送到实例
谁能告诉我原因是什么?
代码:
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
{
return;
}
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = touchMapCoordinate;
point.title = @"Test";
point.subtitle = @"Test2";
for (id annotation in self.mapView.annotations) {
[self.mapView removeAnnotation:annotation];
}
[self.mapView addAnnotation:point];
}
这是我的 ViewDidLoad 方法中的内容:
if (_isSelectLocation)
{
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPressGestureRecognizer.minimumPressDuration = 0.5;
[self.mapView addGestureRecognizer:longPressGestureRecognizer];
}
添加堆栈跟踪:
Stack trace : (
0 Lookcounter 0x0000000100145680 -[MapViewController handleLongPress:] + 1016
1 UIKit 0x000000018a2ceec4 <redacted> + 276
2 UIKit 0x000000018a168508 <redacted> + 580
3 UIKit 0x000000018a5d9214 <redacted> + 60
4 UIKit 0x000000018a12c26c <redacted> + 292
5 UIKit 0x000000018a12a618 <redacted> + 2504
6 CoreFoundation 0x0000000185673ff0 <redacted> + 32
7 CoreFoundation 0x0000000185670f7c <redacted> + 360
8 CoreFoundation 0x000000018567135c <redacted> + 836
9 CoreFoundation 0x000000018559cf74 CFRunLoopRunSpecific + 396
10 GraphicsServices 0x000000018eff76fc GSEventRunModal + 168
11 UIKit 0x000000018a19ed94 UIApplicationMain + 1488
12 Lookcounter 0x00000001001418d0 main + 124
13 libdyld.dylib 0x0000000197a32a08 <redacted> + 4
)
【问题讨论】:
-
代码中是否有一个地方可以向对象发送
index消息?您发布的代码看起来不错。您还可以发布整个堆栈跟踪吗? -
我编辑了我的帖子以显示它。这就是你要找的东西吗?
-
是的,尽管编辑的部分很奇怪且没有提供信息。您能否添加一个异常断点 (developer.apple.com/library/ios/recipes/…) 或逐步调试您的处理程序并告诉我们它在哪一行准确地失败了?它总是发生,还是第二次/第三次/等触摸?您还在哪个设备(如果是模拟器)和 iOS 版本上获得这些?
标签: ios dictionary annotations selector