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

来源:互联网 发布:算法的发展成果 编辑:程序博客网 时间:2024/06/07 07:23

直接上代码: 


       NSString *firstCellID =@"firstCellID";

        MyAlbumFirstCell *firstCell = [tableViewdequeueReusableCellWithIdentifier:firstCellID];  

        if (firstCell ==nil)

        {

           firstCell = [[MyAlbumFirstCellalloc] initWithStyle:UITableViewCellStyleDefault                                                                                reuseIdentifier:firstCellID];

        }

        UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizeralloc]

                                          initWithTarget:selfaction:@selector(cellLongPress:)];  

        [firstCell addGestureRecognizer:longPressGesture];

        return firstCell;



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

- (void)cellLongPress:(UILongPressGestureRecognizer *)cellLongPress

{

    if (cellLongPress.state ==UIGestureRecognizerStateBegan)

    {

        CGPoint point = [cellLongPresslocationInView:_tableView];

        NSIndexPath *indexPath = [_tableViewindexPathForRowAtPoint:point];

        

        if (indexPath !=nil)

        {

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

        }

    }

}

0 0
原创粉丝点击