【问题标题】:Unrecognized Selector [MKPointAnnotation index]无法识别的选择器 [MKPointAnnotation index]
【发布时间】: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


【解决方案1】:

我不确定是什么问题。我已经复制了你所有的代码,并且运行良好。我把它作为一个项目发布在 github 上。

https://github.com/zhangjianxing/trySelectorApp

我相信还有其他原因导致编译器无法识别选择器(如果您将“handleLongPress”设置为私有,则会出现同样的错误)。

我建议你评论其他方法/属性,然后再试一次。

【讨论】:

  • 它最终成为委托方法之一。特别是 viewForAnnotation。
  • 很高兴你能找到它。但是为什么“viewForAnnotation”会导致“handleLongPress”无法识别。委托中是否有一些具有相同名称的私有函数?
  • 我在应用程序中将自定义注释用于其他目的,它具有通用注释没有的属性。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多