UITableView的cell的点击

虽然是tableview中cell的长按手势  但是手势是添加在tableview上的  

UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(pressAction:)];
[self.tableView addGestureRecognizer:longpress];

- (void)pressAction:(UILongPressGestureRecognizer *)longPressGesture
{
if (longPressGesture.state == UIGestureRecognizerStateBegan) {//手势开始
CGPoint point = [longPressGesture locationInView:self.tableView];
NSIndexPath *currentIndexPath = [self.tableView indexPathForRowAtPoint:point]; // 可以获取我们在哪个cell上长按
NSLog(@"%ld",currentIndexPath.section);
}
if (longPressGesture.state == UIGestureRecognizerStateEnded)//手势结束
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否删除" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];

[alert show];

}
}

 

参考链接

https://www.cnblogs.com/dujiahong/p/10676877.html

 

posted on 2016-04-16 11:23  🌞Bob  阅读(298)  评论(0编辑  收藏  举报

导航