您的位置:首页 > 其它

TablView长按手势执行两次的问题

2016-06-20 21:01 295 查看
直接上代码: 

       NSString *firstCellID =
@"firstCellID";

        MyAlbumFirstCell *firstCell = [tableView
dequeueReusableCellWithIdentifier:firstCellID];  

        if (firstCell ==
nil)

        {

           firstCell = [[MyAlbumFirstCell
alloc] initWithStyle:UITableViewCellStyleDefault                                                   
                            reuseIdentifier:firstCellID];

        }

        UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer
alloc]

                                          initWithTarget:self
action:@selector(cellLongPress:)];  

        [firstCell addGestureRecognizer:longPressGesture];

        return firstCell;

#pragma mark - cell长按手势触发的方法

- (void)cellLongPress:(UILongPressGestureRecognizer *)cellLongPress

{

    if (cellLongPress.state ==
UIGestureRecognizerStateBegan)

    {

        CGPoint point = [cellLongPress
locationInView:_tableView];

        NSIndexPath *indexPath = [_tableView
indexPathForRowAtPoint:point];

        

        if (indexPath !=
nil)

        {

            NSLog(@"%ld", indexPath.row);

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: