• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:52:38 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试通过触摸 map View 添加注释,在我释放新闻后,我收到此错误:

[MKPointAnnotation index] : unrecognized selector sent to instance



谁能告诉我原因是什么?

代码:
- (void)handleLongPressUIGestureRecognizer *)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 actionselector(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
)  



Best Answer-推荐答案


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

https://github.com/zhangjianxing/trySelectorApp

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

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

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap