为什么这个 TouchBegan 方法代码会在我的 UITableView 中触发?
为什么在我的UITableView中touchesBegan方法代码会被触发?
背景:我在 UINavigationController 中有一个 UITableView。在 UITableView 中,我有基于子类化 UITableViewCell 的自定义单元格。我当前的 UITableView 中没有 selectRowAtIndexPath 方法。
答案中最好掩盖的一些方面包括:
为什么它显然不起作用
就让它起作用而言,如何得到确保正确的触摸(单击)检测不会阻止其他场景的工作,例如:选择表格行、上下滚动表格视图内容等。
模拟器是否应该能够检测到触摸等,或者是否存在您需要物理设备的情况
代码:
@interface AppointmentListController : UITableViewController <UIActionSheetDelegate>
.
.
.
@implementation AppointmentListController
.
.
.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
timeStampStart = event.timestamp;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSTimeInterval timeStampEnd = event.timestamp;
NSTimeInterval touchDuration = timeStampEnd - timeStampStart;
if(touchDuration > 0.2)
[super touchesEnded:touches withEvent:event];
else
DLog(@" - TOUCH EVENT OCCURS");
[super touchesEnded:touches withEvent:event];
}
Why does the touchesBegan method code get trigger in my UITableView?
Background: I have a UITableView within a UINavigationController. In the UITableView I have custom cells based on subclassing UITableViewCell. I current don't have a selectRowAtIndexPath method in my UITableView.
Some aspects of the answer that would be good to cover off would include:
why it doesn't work obviously
in terms of getting it to work, how does get one ensure that the correct touch (single-tap) detection will not prevent the other scenarios to work like: selecting a table row, scrolling the tableview contents up and down etc.
should the simulator be able to pick up touches etc, or are there cases here where you need the physical device
Code:
@interface AppointmentListController : UITableViewController <UIActionSheetDelegate>
.
.
.
@implementation AppointmentListController
.
.
.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
timeStampStart = event.timestamp;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSTimeInterval timeStampEnd = event.timestamp;
NSTimeInterval touchDuration = timeStampEnd - timeStampStart;
if(touchDuration > 0.2)
[super touchesEnded:touches withEvent:event];
else
DLog(@" - TOUCH EVENT OCCURS");
[super touchesEnded:touches withEvent:event];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想要将此作为一个可能的答案,答案是没有相对直接的方法来实现我所要求的目标。这是在 UITableView 页面中检测点击或双击的一种方法,该页面已经检测到行触摸并向上/向下滚动等。
尚未验证是否是这种情况,但人们可以向上-如果他们认为这是真的,请投票这个答案。
Wanted to put up this as a possible answer, the answer being there is no relative straight way to achieve what I've asked for this. That is a way for a tap or double-tap to be detected in a UITableView page, which is already picking up row touches and scroll up/down etc.
Haven't verified whether this is the case or not, but people could up-vote this answer if they believe this to be true.