我試圖通過觸摸即可添加註釋到一個MapView後,我鬆開按我得到這個錯誤:無法識別選擇[MKPointAnnotation指數]
[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
)
在你的代碼中,你發送一個'index'消息給一個對象嗎?你發佈的代碼看起來很好。你還可以發佈整個堆棧跟蹤嗎? – Losiowaty
我編輯了我的帖子以顯示它。那是你在找什麼? – linuxer
是的,雖然編輯部分是奇怪的,沒有信息。您可以添加一個異常斷點(https://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html)或者逐步調試您的處理程序,並告訴我們它究竟在哪一行發生故障?它總是發生,還是第二次/第三次/等觸摸?也在哪些設備(如果模擬器)和iOS版本你是否得到這些? – Losiowaty