She*_*lam 5 iphone cocoa-touch objective-c uitableview uigesturerecognizer
我正在使用手势识别器:
初始化viewDidLoad:
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.view addGestureRecognizer:longPressRecognizer];
Run Code Online (Sandbox Code Playgroud)
这是longPress看起来像:
- (void)longPress:(UILongPressGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.minimumPressDuration == 2.0) {
NSLog(@"Pressed for 2 seconds!");
}
}
Run Code Online (Sandbox Code Playgroud)
我该怎么把它绑成?
- (void)tableView:(UITableView *)tblView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
didSelectRowAtIndexPath将如何获取引用gestureRecognizer.minimumPressDuration?
基本上我想要实现的是:
**If a user clicks on a cell, check to see if the press is 2 seconds.**
Run Code Online (Sandbox Code Playgroud)
尝试通过提供 tableView:willDisplayCell:forRowAtIndexPath: 方法将其添加到 UITableViewCell 而不是 UITableView,如下所示:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell addGestureRecognizer:longPressRecognizer];
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3343 次 |
| 最近记录: |