Ios 触摸UITableview的事件

Ios 触摸UITableview的事件,ios,uitableview,event-handling,hittest,touch-event,Ios,Uitableview,Event Handling,Hittest,Touch Event,我有一个UIView覆盖子类UITableview。问题是,我无法使tableview滚动。我已尝试覆盖触摸开始,触摸移动,触摸取消。然后我试图覆盖hittest,但这似乎没有任何影响 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchPoint = [touch locationInView:se

我有一个
UIView
覆盖子类
UITableview
。问题是,我无法使tableview滚动。我已尝试覆盖
触摸开始
触摸移动
触摸取消
。然后我试图覆盖hittest,但这似乎没有任何影响

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self];
    NSLog(@"SMTable.touches began %@",NSStringFromCGPoint(touchPoint));
    [super touchesBegan:touches withEvent:event];

}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self];
    NSLog(@"SMTable.touches moved %@ for :%p",NSStringFromCGPoint(touchPoint),touch.view);
    [super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self];
    NSLog(@"SMTable.touches ended %@",NSStringFromCGPoint(touchPoint));
    [super touchesEnded:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
    [super touchesCancelled:touches withEvent:event];
}
- (UIView*) hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    //NSLog(@"SMTable.hitTest %@",NSStringFromCGPoint(point));
    return [super hitTest:point withEvent:event];
}

如果您的
UIView
位于
UITableView
上方,则所有触摸事件都将进入该
UIView
,并且您的
UITableView
将不会滚动。当您需要创建一个专门的
UITableView
时,您需要禁用最顶级的“UIView”的交互功能,而不是尽可能在
UITableView
层次结构中混日子,使用包含
UITableView
UIViewController
几乎总是会更好。苹果在tableview层次结构中做了很多工作,这使得在其中添加自定义视图经常出错。因此,简单的答案是:避免将您自己的视图插入到tableView层次结构中

事实上,我几乎不再使用
UITableViewController
子类。我总是发现自己需要以
UITableViewController
不易支持的方式自定义视图控制器,例如创建一个视图以覆盖当前的tableView。相反,请按如下方式创建控制器:

@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic,strong) IBOutlet UITableView *tableView

@end
@接口MyViewController:UIViewController
@属性(非原子,强)IBUITableView*tableView
@结束

如果使用的是Interface Builder,请将tableView放到视图控制器的视图中,并将委托和数据源设置为视图的所有者。也可以通过
viewDidLoad
方法在代码中执行相同的操作。在任何一种情况下,此时您都可以将视图控制器视为一个UITableViewController,这样做的另一个好处是能够在不出现严重错误的情况下将视图插入到self.view中。

OverlyView.userInteractionEnabled=NO;我不认为这会起作用,因为我也需要截取OverlyView的触摸事件