当我在任何地方按下地图视图时,由于未捕获的异常,地图已终止。
-[MapViewController handleGuesture]: unrecognized selector sent to instance 0xa046cc0 2013-04-15 10:41:23.316 CabServiceProvider[912:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapViewController handleGuesture]: unrecognized selector sent to instance 0xa046cc0'
Here is code which is causing this error.
- (void)viewDidLoad{
[super viewDidLoad];
[self.mapView.userLocation addObserver:self
forKeyPath:@"location"
options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
context:NULL];
mapView.userTrackingMode=YES;
[mapView setUserTrackingMode:MKUserTrackingModeFollow];
UITapGestureRecognizer *gr=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleGuesture)];
gr.numberOfTapsRequired=1;
[mapView addGestureRecognizer:gr];
}
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer{
if (gestureRecognizer.state != UIGestureRecognizerStateEnded)
return;
CLLocationCoordinate2D coordinate; //= annotationView.annotation.coordinate;
NSLog(@"dropped at %f,%f", coordinate.latitude, coordinate.longitude);
CGPoint touchPoint = [gestureRecognizer locationInView:mapView];
coordinate = [mapView convertPoint:touchPoint toCoordinateFromView:mapView];
NSLog(@"latitude %f longitude %f",coordinate.latitude,coordinate.longitude);
}
请帮助解决此错误的原因。
答案 0 :(得分:1)
按照我的想法更改此行。
UITapGestureRecognizer *gr=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleGuesture:)];
-------------------------------------------------------------------------------------------------------------^
在传递参数时,您需要添加:
handleGuesture
。
请检查
答案 1 :(得分:1)
好的,请查看此行:
UITapGestureRecognizer *gr=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleGesture:)];
当你打电话给你的方法时,你也会用错误的拼写来打电话。