iOS UITableView添加长按事件 —— HERO博客
2016-07-20 18:08
337 查看
为UITableView添加长按事件,长按cell时获取到当前位置:
1. 为UITableView添加长按手势识别器
2. 实现长按事件方法
1. 为UITableView添加长按手势识别器
//添加长按事件 UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPressTableViewCell:)]; gesture.minimumPressDuration = 1.0; [self.tableView addGestureRecognizer:gesture];
2. 实现长按事件方法
//tableViewCell长按事件 - (void)didLongPressTableViewCell:(UILongPressGestureRecognizer *)gesture { if (gesture.state == UIGestureRecognizerStateBegan) { //获取到点击的位置 CGPoint point = [gesture locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point]; if(indexPath == nil) return; //do something... } }
相关文章推荐
- Mac 下 Mosquitto 安装和配置 (Mosquitto为开源的mqtt服务器)
- 初学IOS_UI基础,滑动面板_XIB框架版_有GIF图_有源文件
- Leetcode-longest-consecutive-sequence
- 字符串只保留开头跟最后一个字符
- BlockingQueue
- buildroot的使用之如何配置使用已安装的cross-compile
- AndroidStudio导入项目一直卡在Building gradle project info最快速解决方案
- 隐藏软键盘与弹窗总结
- UITableViewCell 令人蛋疼的分割线!!!!
- hdu 4390 Number Sequence
- UIView点击事件。弹出视图,背景虚化。
- Ring3下Hook NtQueryDirectoryFile隐藏文件
- Media Queries
- [YY题]HDOJ5288 OO’s Sequence
- leetcode 375. Guess Number Higher or Lower II
- Android 开发最佳实践教程——MVPBuilder
- 自定义可动画展开收缩View的实现
- UICollectionView详解
- 40.You have statistics collected for some selected tables. Your requirement is that the statistics
- 让超出父视图范围的子视图响应事件,在UIView范围外响应点击