0

为什么 touchesBegan 方法代码会在我的 UITableView 中触发?

背景:我在 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];
    }
4

1 回答 1

0

想把这个作为一个可能的答案,答案是没有相对直接的方法来实现我所要求的。这是在 UITableView 页面中检测到点击或双击的一种方式,该页面已经在拾取行触摸和向上/向下滚动等。

尚未验证是否是这种情况,但如果人们相信这是真的,他们可以投票赞成这个答案。

于 2011-03-27T03:59:12.013 回答