【发布时间】:2015-07-01 05:45:45
【问题描述】:
如果用户进行了一次触摸,我想执行一个操作,如果用户在 UITableView 单元上进行了两次触摸,我想执行另一个操作。
我尝试了这个问题中提到的多种方法。
How can I detect a double tap on a certain cell in UITableView?
但是每种方法,我都无法正确区分单击和双击。我的意思是,在每次双击中,它也会发生一次单击。所以,双击发生,每次单击动作也会触发。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
FeedCell *myCell = (FeedCell*) [self.tblView cellForRowAtIndexPath:indexPath];
NSLog(@"clicks:%d", myCell.numberOfClicks);
if (myCell.numberOfClicks == 2) {
NSLog(@"Double clicked");
}
else{
NSLog(@"Single tap");
}
}
这样做的正确方法应该是什么?
【问题讨论】:
-
使用长按手势
-
在哪里增加numberOfClicks的值?你在哪里捕捉到双击?
-
在 CustomTableViewCell 中
-
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *aTouch = [touches anyObject]; self.numberOfClicks = [aTouch tapCount]; [超级 touchesEnded:touches withEvent:event]; }
标签: ios objective-c iphone uitableview