2014-11-25 5 views
0

나는이UILongPressGestureRecognizer 핸들러

UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleGestureSection:)]; 

[gesture view].tag = indexPath.row; 
gesture.minimumPressDuration = 0.5; 
gesture.allowableMovement = 600; 
[cell addGestureRecognizer:gesture]; 

같은 셀에 제스처를 추가하고 있는데이 indexPath.row를 얻기 위해 노력하고 있어요에 태그를 반환하지 않습니다

  • (무효) handleGestureSection :(UIGestureRecognizer *) 제스처 {

    if (gesture.state == UIGestureRecognizerStateEnded) { NSLog (@ "Long press Ended");

    } else if (gesture.state == UIGestureRecognizerStateBegan) { NSInteger i = [제스처보기] .tag; 내가 잘못 뭐하는 거지

그러나 항상 0 을 반환 } }?

답변

0

UIGestureRecognizer에서보기가 nil이므로 0이됩니다.

먼저 모든 셀에 UIGestureRecognizer를 추가해야합니다.

UILongPressGestureRecognizer* longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandler:)]; 
longPressGesture.delegate = cell; 
[longPressGesture setMinimumPressDuration:2.0]; 
[cell addGestureRecognizer:longPressGesture]; 
그리고, gestureHandler을 처리 :

UIGestureRecognizer *recognizer = (UIGestureRecognizer*) sender; 
CGPoint p = [recognizer locationInView:self.tableView];  
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];