2013-02-04 65 views
0

我有一个UIView覆盖子类UITableview。问题是,我不能让tableview滚动。我试过压倒touchesBegan,touchesMoved,touchesEnded。然后我试图覆盖hittest,但似乎没有任何影响。触摸UITableview事件

-(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]; 
} 
+0

overlayView.userInteractionEnabled = NO; –

回答

1

如果UIView是你UITableView以上,那么所有触摸事件,将在UIView土地和你UITableView不会滚动。你需要禁用的互动为您最上面的`UIView~

+0

我不认为这将工作,因为我需要拦截触摸事件overlayView太 –

+0

您的权利,谢谢! –

0

当你需要创建一个专门UITableView你几乎总是最好使用UIViewController包含UITableView而不是UITableView层次结构,如果在所有可能的出渣周围。 Apple在tableview层次结构中做了很多工作,这会让你自己定制的视图经常出错。所以,简短的回答是:避免将自己的视图插入到tableView层次结构中。

事实上,我几乎从不再使用UITableViewController子类。我总是发现自己需要以一种不易从UITableViewController支持的方式定制视图控制器 - 例如创建一个视图来覆盖tableView。相反,创建你的控制器是这样的:

@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> 

@property (nonatomic,strong) IBOutlet UITableView *tableView 

@end 

如果使用界面生成器,降低你的tableView到视图控制器的观点,并设置委托和数据源到视图的所有者。或者您可以通过viewDidLoad方法在代码中执行相同的操作。在这两种情况下,在这一点上,你可以把视图控制器看作是一个UITableViewController,它的好处是能够做一些事情,比如将视图插入到self.view中,而不会出现任何可怕的错误。