Objective c 刷卡时无法识别选择器

Objective c 刷卡时无法识别选择器,objective-c,ios,cocoa-touch,unrecognized-selector,Objective C,Ios,Cocoa Touch,Unrecognized Selector,我只需要在特殊区域进行刷卡操作。但调试器告诉发送到实例的选择器无法识别 - (void)viewDidLoad { UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self.viewName action:@selector(didSwipe:)]; swipeLeft.direction = UISwipeGestureRecogni

我只需要在特殊区域进行刷卡操作。但调试器告诉
发送到实例的选择器无法识别

- (void)viewDidLoad
{
    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]
          initWithTarget:self.viewName action:@selector(didSwipe:)];
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeLeft];
}

-(void)didSwipe:(UISwipeGestureRecognizer*)swipe{
   NSLog(@"swiped left");
}

怎么了?

您的手势识别器有一个参数,因此应该是
@selector(didSwipe:)
(注意冒号)。

您可能希望目标是
self
而不是
self.imageName


编辑以回应您的评论

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]
      initWithTarget:self action:@selector(didSwipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.viewName addGestureRecognizer:swipeLeft];

您希望您的
目标
是方法所在的位置。在这种情况下,应该是
self
。您想将您的手势识别器添加到应该触摸的视图中,
self.viewName

好吧,它确实有效,但适用于所有屏幕。我怎么能只有在特殊区域才做这个手势呢?即使不是这样。我需要的是,除了smal区域外,刷卡在任何地方都不起作用:)如果需要在某个区域,则不应将手势识别器添加到整个
self.view
。尝试将其添加到子视图中,该子视图位于您希望用户滑动的正确位置。创建UIView viewName时也会出现同样的问题。我只是不知道用target在init中写什么。我在上面编辑了我的回复。如果我能澄清任何其他事情,请告诉我。