2013-02-04 63 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中,而不會出現任何可怕的錯誤。