ios - 无法识别的选择器 [MKPointAnnotation 索引]
<p>我正在尝试通过触摸 mapView 添加注释,在我释放新闻后,我收到此错误:<br><br> <blockquote>
<p> : unrecognized selector sent to instance</p>
</blockquote><br><br>谁能告诉我原因是什么?<br><br>代码:<br><pre><code>- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
{
return;
}
CGPoint touchPoint = ;
CLLocationCoordinate2D touchMapCoordinate = ;
MKPointAnnotation *point = [ init];
point.coordinate = touchMapCoordinate;
point.title = @"Test";
point.subtitle = @"Test2";
for (id annotation in self.mapView.annotations) {
;
}
;
}
</code></pre><br>这是我在 <strong> ViewDidLoad </strong> 方法中的内容:<br><pre><code>if (_isSelectLocation)
{
UILongPressGestureRecognizer *longPressGestureRecognizer = [ initWithTarget:self action:@selector(handleLongPress:)];
longPressGestureRecognizer.minimumPressDuration = 0.5;
;
}
</code></pre><br>添加堆栈跟踪:<br><pre><code>Stack trace : (
0 Lookcounter 0x0000000100145680 - + 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
10GraphicsServices 0x000000018eff76fc GSEventRunModal + 168
11UIKit 0x000000018a19ed94 UIApplicationMain + 1488
12Lookcounter 0x00000001001418d0 main + 124
13libdyld.dylib 0x0000000197a32a08 <redacted> + 4
)
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p>我不确定是什么问题。我已经复制了您的所有代码,并且运行良好。我把它作为一个项目发布在 github 上。<br><br> <a href="https://github.com/zhangjianxing/trySelectorApp" rel="noreferrer noopener nofollow">https://github.com/zhangjianxing/trySelectorApp</a><br><br>我相信还有其他原因导致编译器无法识别选择器(在 swift 中,如果您将“handleLongPress”设置为私有(private),则会出现相同的错误)。<br><br>我建议您评论其他方法/属性,然后重试。</p>
<p style="font-size: 20px;">关于ios - 无法识别的选择器 ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32052498/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32052498/
</a>
</p>
页:
[1]