uitableviewcell添加长按手势 并获取cell
来源:互联网 发布:各种算法时间复杂度 编辑:程序博客网 时间:2024/05/23 23:04
http://mobile.51cto.com/iphone-403791.htm
- UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
- lpgr.minimumPressDuration = 1.0; //seconds 设置响应时间
- lpgr.delegate = self;
- [mTableView addGestureRecognizer:lpgr]; //启用长按事件
- [lpgr release];
- -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer //长按响应函数
- {
- CGPoint p = [gestureRecognizer locationInView:mTableView ];
- //if(gestureRecognizer.state == UIGestureRecognizerStateBegan)
- //{
- //NSLog(@"UIGestureRecognizerStateBegan");
- //}
- //else if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
- //{
- //NSLog(@"UIGestureRecognizerStateEnded");
- //}
- //else if(gestureRecognizer.state == UIGestureRecognizerStateChanged)
- //{
- //NSLog(@"UIGestureRecognizerStateChanged");
- //}
- //else if(gestureRecognizer.state == UIGestureRecognizerStateCancelled)
- //{
- //NSLog(@"UIGestureRecognizerStateCancelled");
- //}
- //else if(gestureRecognizer.state ==UIGestureRecognizerStateFailed )
- //{
- //NSLog(@"UIGestureRecognizerStateFailed");
- //}
- NSIndexPath *indexPath = [mTableview indexPathForRowAtPoint:p];//获取响应的长按的indexpath
- if (indexPath == nil)
- NSLog(@"long press on table view but not on a row");
- else
- NSLog(@"long press on table view at row %d", indexPath.row);
- }
给UITableView 添加长按手势,识别长按哪一行。
长按手势类UILongPressGestureRecognizer, 属性minimumPressDuration表示最短长按的时间
添加手势代码:
- UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
- longPressGr.minimumPressDuration = 1.0;
- [self.tableView addGestureRecognizer:longPressGr];
- [longPressGr release];
响应长按事件代码:
- -(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
- {
- if(gesture.state == UIGestureRecognizerStateBegan)
- {
- CGPoint point = [gesture locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];
- if(indexPath == nil) return ;
- //add your code here
- }
- }
0 0
- uitableviewcell添加长按手势 并获取cell
- uitableviewcell添加长按手势
- 在cell上添加长按手势,并给手势添加tag值
- UITableViewCell添加长按手势问题
- iOS - UITableViewCell 添加长按手势(别的手势类似):
- 在cell中添加长按手势弹出UIAlertView
- 获取长按手势所点击的cell的行号
- UITableViewCell中自定义cell添加手势没有响应解决方案
- IOS给tableview的cell添加长按手势执行两次(UILongPressGestureRecognizer)
- btn 添加长按手势
- UITableViewCell中自定义cell上UILabel添加手势没有响应解决方案
- 根据点击头像的手势获取自定义Cell 的属性, UITableViewCell, 头像, iOS
- iOS自定义长按手势,随意拖动Cell
- 利用长按手势移动TableView中的Cell
- tableView左滑删除,自定义标题+cell长按手势
- cell长按手势真机无法识别问题
- UITableView 添加长按手势UILongPressGestureRecognizer
- spritekit中添加长按手势操作
- POJ-3069 Saruman's Army
- 1-100能整除3的前5个数
- 自然语言处理NLP常用开源/免费工具
- Android-使用AutoCompleteTextView进行动态匹配
- 手势锁
- uitableviewcell添加长按手势 并获取cell
- 浅谈C++多态性
- 求 1 1 2 3 5 8这种数列的第n个数 迭代法和递归来求
- 一种优秀的异常处理方法
- $POST 、$HTTP_RAW_POST_DATA、php://input三者之间的区别
- 中国剩余定理(韩信点兵)
- hdu 4267 线段树间隔更新
- 指针变量和引用变量的区别
- 好用的快捷键软件