`
119568242
  • 浏览: 420394 次
  • 性别: Icon_minigender_1
  • 来自: 深圳/湛江
社区版块
存档分类
最新评论

[ios]tableViewCell的 长按操作

    博客分类:
  • ios
 
阅读更多

思路1:

对cell增加长按手势。

失败,cell长按手势无法触发。

 

思路2:

1.对tableView增加 长按手势

2.通过手势获取point

3.通过point获取row

 

增加手势

 longPress = [[UILongPressGestureRecognizer alloc]

                                               initWithTarget:self

                                               action:@selector(myHandleTableviewCellLongPressed:)];

 

    longPress.minimumPressDuration = 1.0;

    [self.tableView addGestureRecognizer:longPress];

 

……

 

CGPoint ponit=[gestureRecognizer locationInView:self.tableView];

//获取手势在传入的view的位置  (这里是单点)

//多点- (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView*)view; 

 

NSIndexPath* path=[self.tableView indexPathForRowAtPoint:ponit];

//根据点击的point在table中找到相应的indexpath。

 

 

完整

-(void)tableviewCellLongPressed:(UILongPressGestureRecognizer *)gestureRecognizer{
    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
        NSLog(@"UIGestureRecognizerStateBegan");
        CGPoint ponit=[gestureRecognizer locationInView:self.tableView];
        NSLog(@" CGPoint ponit=%f %f",ponit.x,ponit.y);
        NSIndexPath* path=[self.tableView indexPathForRowAtPoint:ponit];
        NSLog(@"row:%d",path.row);
        currRow=path.row;
    }else if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
    {
        //未用
    }
    else if(gestureRecognizer.state == UIGestureRecognizerStateChanged)
    {
        //未用
    }

    
}

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics