0

UITableViewCell 안에 UITapGestureRecognizer이있는 일부 UILabels를 사용합니다. GestureRecognizer는 잘 작동합니다. 그러나 레이블을 탭하면 didSelectRowAtIndexPath:도 실행해야합니다. 또는 indexPathForSelectedRow() 메서드로도 선택된 행을 제공해야합니다.UITableViewCell 블록 안에 제스쳐 인식기가있는 UILabel didSelectRowAtIndexPath

설정 cancelsTouchesInView = false이 작동하지 않았습니다!

이것이 가능합니까? 지금 indexPathForSelectedRow() 메서드는 nil을 반환합니다. 감사합니다.

답변

3

UITapGestureRecognizer을 왜 사용하고 있습니까? 이를 사용하려면 레이블 태그를 label.tag=indexpath.row으로 설정하십시오. 그래서 당신은 당신이보고있는 가치를 얻을 수 있습니다. 내 자신의 의견에 대해서는, 나는 uitapgesturerecognizer를 제거하고 직접 didselectrowatindexpath 방법 ..

편집 2 사용하십시오 :

.. 당신을 도울 수있는이 solution..it를 사용해보십시오

-(void)handleTap:(UITapGestureRecognizer *)sender 

    { 

CGPoint location = [sender locationInView:self.view]; 

    if (CGRectContainsPoint([self.view convertRect:self.yourTableView.frame fromView:self.tableView.superview], location)) 
    { 
     CGPoint locationInTableview = [self.yourTableView convertPoint:location fromView:self.view]; 
     NSIndexPath *indexPath = [self.yourTableView indexPathForRowAtPoint:locationInTableview]; 
     if (indexPath) 
      [self tableView:self.yourTableView didSelectRowAtIndexPath:indexPath]; 

     return; 
    } 

} 
+0

내가 이상을 사용을 하나의 레이블보다 –

+0

UITapGestureRecognizer를 사용하여 무엇을 할 예정입니까 ?? –

+0

레이블을 탭하면 어레이에 다른 값을 저장하고 어레이 인덱스로 선택한 행이 필요합니다. –

관련 문제