1. UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
  2. lpgr.minimumPressDuration = 1.0; //seconds  设置响应时间
  3. lpgr.delegate = self;
  4. [mTableView addGestureRecognizer:lpgr]; //启用长按事件
  5. [lpgr release];
  6. -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer  //长按响应函数
  7. {
  8. CGPoint p = [gestureRecognizer locationInView:mTableView ];
  9. //if(gestureRecognizer.state == UIGestureRecognizerStateBegan)
  10. //{
  11. //NSLog(@"UIGestureRecognizerStateBegan");
  12. //}
  13. //else if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
  14. //{
  15. //NSLog(@"UIGestureRecognizerStateEnded");
  16. //}
  17. //else if(gestureRecognizer.state == UIGestureRecognizerStateChanged)
  18. //{
  19. //NSLog(@"UIGestureRecognizerStateChanged");
  20. //}
  21. //else if(gestureRecognizer.state == UIGestureRecognizerStateCancelled)
  22. //{
  23. //NSLog(@"UIGestureRecognizerStateCancelled");
  24. //}
  25. //else if(gestureRecognizer.state ==UIGestureRecognizerStateFailed )
  26. //{
  27. //NSLog(@"UIGestureRecognizerStateFailed");
  28. //}
  29. NSIndexPath *indexPath = [mTableview indexPathForRowAtPoint:p];//获取响应的长按的indexpath
  30. if (indexPath == nil)
  31. NSLog(@"long press on table view but not on a row");
  32. else
  33. NSLog(@"long press on table view at row %d", indexPath.row);
  34. }

UITableViewCell 添加长按手势的更多相关文章

  1. ios 实现在tableViewCell上面添加长按手势 删除该条cell以及列表后台数据等

    自己的代码  需要   把属性更改成自己要使用的 //创建长按手势 在cellForRowAtIndexPath代理方法中 UILongPressGestureRecognizer *longPres ...

  2. 给button添加长按手势并侦测到此button

    1, 添加手势 self.longPressRecognizer = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@ ...

  3. iOS 利用长按手势移动 Table View Cells

    本文译自:Cookbook: Moving Table View Cells with a Long Press Gesture 目录: 你需要什么? 如何做? 如何将其利用至UICollection ...

  4. IOS 关于tableview中cell的长按手势

    说明:虽然是tableview中cell的长按手势  但是手势是添加在tableview上的 UILongPressGestureRecognizer *longpress = [[UILongPre ...

  5. Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍

    1.UITapGestureRecognizer 点击/双击手势 代码如下: var tapGesture = UITapGestureRecognizer(target: self, action: ...

  6. iOS长按手势调用两次解决方法

    由于以前没有很细致的研究过长按手势,所以今天使用的时候发现长按手势会调用两次响应事件. 主要原因是长按手势会分别在UIGestureRecognizerStateBegan和UIGestureReco ...

  7. IOS 为UILabel添加长按复制功能

    IOS 为UILabel添加长按复制功能 在iOS中下面三个控件,自身就有复制-粘贴的功能: 1.UITextView 2.UITextField 3.UIWebView UIKit framewor ...

  8. 自定义uitableviewcell通过加上滑动手势进行删除对应的行。PS:用代理来实现

    #import <UIKit/UIKit.h> @class ZSDCustomCell; //协议 @protocol ZSDCustomCellDelegate <NSObjec ...

  9. Swift - 给表格的单元格UITableViewCell添加图片,详细文本标签

    表格UITableView中,每一单元格都是一个UITableViewCell.其支持简单的自定义,比如在单元格的内部,添加图片和详细文本标签. 注意UITableViewCell的style: (1 ...

随机推荐

  1. Android基础之响应Menu键弹出菜单Demo

    对于Android我也不是很熟悉,只是学习一些基本内容就OK.所以写的内容也很简单.本Demo要实现的效果就点击Menu键将弹出一个菜单并响应点击菜单项事件. 一.废话少说直接上代码.其实就是重写两个 ...

  2. 14.6.5 Configuring InnoDB Change Buffering 配置InnoDB Change Buffering

    14.6.5 Configuring InnoDB Change Buffering 配置InnoDB Change Buffering 当插入,更新,和删除操作在表上执行, 索引列的值(特别是 se ...

  3. This configuration file was broken by system-config-keyboard

    posts • Page of problem with startx Postby evarie » // :: Normally i can get started with the x wind ...

  4. 查看Mysql执行计划

    使用navicat查看mysql执行计划: 打开profile分析工具: 查看是否生效:show variable like ‘%profil%’; 查看进程:show processlist; 选择 ...

  5. HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))

    Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  6. [XenServer] XenServer修改IP 以及 root密码

     A.修改IP以及DNS 1. root用户登录console 2.输入命令获得UUID xe pif-list 3.利用UUID查看之前的IP,注意替换下面的1111111111 xe pif-pa ...

  7. HDOJ 2017 字符串统计

    Problem Description 对于给定的一个字符串,统计其中数字字符出现的次数. Input 输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组 ...

  8. PHP中Content-type的MIME类型大全说明

    <?php $mimetypes = array(         'ez' => 'application/andrew-inset', 'hqx' => 'application ...

  9. centos_6.7_系统初始化

    #!/bin/bash #****************************************************************# # ScriptName: acfunin ...

  10. poj3693 Maximum repetition substring

    题意 给出一个长度为\(n(n\leqslant 100000)\)的串,求一个字典序最小的子串使得它是某个字符串重复\(k\)次得到的,且\(k\)最大 题解 后缀数组论文上的题,跟上一篇uva那个 ...