-1

当我在任何地方按下地图视图时,地图由于未捕获的异常而终止。

-[MapViewController handleGuesture]:无法识别的选择器发送到实例 0xa046cc0
2013-04-15 10:41:23.316 CabServiceProvider [912:c07] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[MapViewController handleGuesture]:无法识别的选择器发送到实例 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);
}

请帮助为什么会出现此错误。

4

2 回答 2

1

好的检查这一行:

UITapGestureRecognizer  *gr=[[UITapGestureRecognizer alloc]initWithTarget:self        action:@selector(handleGesture:)];

当你调用你的方法时,你也会用错误的拼写调用。

于 2013-04-15T06:27:49.870 回答
1

按照我的想法改变这条线。

UITapGestureRecognizer *gr=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleGuesture:)];
-------------------------------------------------------------------------------------------------------------^

您需要在传递参数时添加:with 。handleGuesture

请检查

于 2013-04-15T06:16:51.563 回答