ios - 无法识别的选择器 [MKPointAnnotation 索引]

标签 ios dictionary annotations selector

我正在尝试通过触摸在 map View 上添加注释,但在我松开按键后出现此错误:

[MKPointAnnotation index] : unrecognized selector sent to instance

谁能告诉我原因是什么?

代码:

- (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
)  

最佳答案

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

https://github.com/zhangjianxing/trySelectorApp

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

我建议您评论其他方法/属性,然后重试。

关于ios - 无法识别的选择器 [MKPointAnnotation 索引],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32052498/

相关文章:

python - 从输入访问字典内的列表

ios - 如何在像 Trello 应用程序这样的单元格中具有 UITableView 的 UICollectionView 中进行拖放

objective-c - iOS中的非延迟图像加载

Javascript - 向键添加多个值

javascript - 传单 map 背景图 block 显示为断开的链接

java - 如何为 JRE 方法中的参数定义 Eclipse 外部空注释

java - 玩!框架 renderJson 未公开特定字段

spring - 关于Spring的@Autowired和Wicket的@SpringBean

iphone - UIButton上的弹出窗口在设备上非常慢

ios - 我必须实现 UIDataSourceModelAssociation 吗?