zoukankan      html  css  js  c++  java
  • ios开发-给cell添加长按手势

    业务需要给cell添加一个长按手势

    //需要在这个方法里添加
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
     //添加长按手势
        UILongPressGestureRecognizer * longPressGesture =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(cellLongPress:)];
        
        longPressGesture.minimumPressDuration=1.5f;//设置长按 时间
        [cell addGestureRecognizer:longPressGesture];
    
     return cell;
    }
     -(void)cellLongPress:(UILongPressGestureRecognizer *)longRecognizer{
        
        
        if (longRecognizer.state==UIGestureRecognizerStateBegan) {
          //成为第一响应者,需重写该方法
            [self becomeFirstResponder];
    
         CGPoint location = [longRecognizer locationInView:self.tableView];
            NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
    //可以得到此时你点击的哪一行
    
       //在此添加你想要完成的功能
    
    }
    
    
    }
    #pragma mark  实现成为第一响应者方法
    -(BOOL)canBecomeFirstResponder{
        return YES;
    }
  • 相关阅读:
    git 常用命令
    centos 7 mini 安装
    python打印杨辉三角
    python 求100内的素数/质数
    字符串与bytes
    format
    Python字符串格式化
    数据结构
    ARM工作模式
    C语言实现字符串逆序输出
  • 原文地址:https://www.cnblogs.com/oldk/p/5438355.html
Copyright © 2011-2022 走看看