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;
    }
  • 相关阅读:
    lombok 的使用
    SpringData Redis 常见操作(基于模板类RedisTemplate )
    Django,静态文件配置
    django简介与MTV,MVC
    HTTP请求响应,及工作原理
    阿萨斯

    javastrip
    css
    html
  • 原文地址:https://www.cnblogs.com/oldk/p/5438355.html
Copyright © 2011-2022 走看看