tableview长按响应的实现

1、添加手势识别事件、按住时长、处理函数

 UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];

 longPressGr.minimumPressDuration = 0.8;

 [self.tableView addGestureRecognizer:longPressGr];

 [longPressGr release];

2、实现UIAlertView 的代理方法(如果需要弹出提示)

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

3、实现处理函数

longPressToDo:

通过点击的坐标来判断点击了哪一个cell

if(gesture.state == UIGestureRecognizerStateBegan)

    {

        CGPoint point = [gesture locationInView:self.tableView];

        NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];

         if(indexPath == nil) return ;

}

 

posted @ 2016-02-26 17:03  wangbaixue  阅读(297)  评论(0编辑  收藏  举报