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. 利用merge优化

    create table a1(TP_END_DATE NUMBER,WK_END_DATE NUMBER, MTH_START_DATE NUMBER, MTH_END_DATE NUMBER, T ...

  2. java 集合框架图

    Java平台提供了一个全新的集合框架.“集合框架”主要由一组用来操作对象的接口组成.不同接口描述一组不同数据类型. Java 2集合框架图集合接口:6个接口(短虚线表示),表示不同集合类型,是集合框架 ...

  3. 【HDOJ】2888 Check Corners

    二维RMQ. /* 2888 */ #include <iostream> #include <algorithm> #include <cstdio> #incl ...

  4. Win7 64位系统U盘安装Centos6.5双系统

    (win764位旗舰版系统 Centos6.5亲测成功) 安装前准备: U盘.软碟通(UltraISO).CentOS-6.5-x86_64-bin-DVD1(DVD 2只是一些软件,安装系统只要DV ...

  5. Defining as a "long" or "int" type throws an error on startup

    solr启动时候,报如下异常: [java] view plaincopy SEVERE: org.apache.solr.common.SolrException          at org.a ...

  6. QTP自动化测试权威指南 连载(一)

    第一章 简介 什么是自动化测试 自动化测试是对一个已有的手工测试过程减少并尽可能排除人工干预的过程. 什么时候适合做自动化测试 下面是一组适合将手工测试自动化的考量因素: ● 测试需要经常重复. ● ...

  7. NOI题库05 派

    05:派 Description 我的生日要到了!根据习俗,我需要将一些派分给大家.我有N个不同口味.不同大小的派.有F个朋友会来参加我的派对,每个人会拿到一块派(必须一个派的一块,不能由几个派的小块 ...

  8. ubuntu14.04 wps字体缺失问题

    字体 下载安装字体即可

  9. 使用 环境变量 来配置批量配置apache

    使用apache的DAV假设了一个GIT仓库.需要为每个项目写一个配置项, 配置内容如下 <directory "/srv/abcdfdfdjkdfjkgjjdhjklfdjjfdfd ...

  10. STL之deque、queue、stack、list

    首先deque和vector是很像的 但是de代表double双向的队列那么deque可以从首部添加(删除)元素也可以从尾部添加(删除)元素. .push_back(elem) .push_front ...