2

特別なエリアでのみスワイプアクションをキャッチする必要があります。しかし、デバッガーはunrecognized selector sent to instance

- (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");
}

どうしたの?

4

2 に答える 2

6

ジェスチャレコグナイザーには引数があるので、そうする必要があります@selector(didSwipe:)(コロンに注意してください)。

于 2012-03-20T16:15:01.747 に答える
3

あなたはおそらくターゲットをしたくないでしょselfself.imageName


コメントに応じて編集します。

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

あなたはあなたtargetがその方法が生きる場所になりたいのです。この場合、それはであるはずですself。タッチすることになっているビューにジェスチャレコグナイザーを追加しますself.viewName

于 2012-03-20T16:29:38.850 に答える