通過UITableViewCell獲取indexPath

UITableView中給每個UITableViewCell添加一個長按手勢,在長按手勢觸發時,不會觸發tableviewdidSelectRowAtIndexPath方法,這樣就不知道長按的是哪個cell,有一種簡單的方法可以獲得cell所在的indexPath

-(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
{
    
    if(gesture.state == UIGestureRecognizerStateBegan)
    {
        CGPoint point = [gesture locationInView:self.tableView];
         
        NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];
         
        if(indexPath == nil) return ;
 
       //add your code here
         
 
         
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章