2010-02-23 66 views
0

我有問題。我有一個UIView,看起來像這樣:alt text http://img193.imageshack.us/img193/6641/img0157y.png如何在我的UIView中正確檢測觸摸?

在該視圖控制器我實現了「touchesBegan:withEvent:」方法,但該方法只有在觸摸視圖底部的欄時纔會觸發,當我碰到桌子時發生。

我怎麼能改變這種行爲,以便能夠檢測表中發生的觸摸呢?

這是一個基本聲明的UIViewController代碼:

#import <Foundation/Foundation.h> 
#import <QuartzCore/QuartzCore.h> 

@interface TripSearchDetailViewController : UIViewController 
{ 
    //Parent of this sub-view. 
    UIViewController *parentController; 

    //GUI elements 
    UITableView   *tableView; 
    UIButton   *backButton; 
} 

//Button actions 
- (IBAction) goBack:(id) sender; 
- (IBAction) showDatePicker:(id) sender; 

//Class Methods. 
- (void) presentDatePicker; 


@property (nonatomic, retain) UIViewController  *parentController; 
@property (nonatomic, retain) IBOutlet UITableView *tableView; 
@property (nonatomic, retain) IBOutlet UIButton  *backButton; 

@end 

回答

2

看起來你已經有了一個UITableViewController,不是一個UIViewController。您的表格視圖在將視圖合併到視圖控制器之前會截取並處理觸摸。你需要繼承UITableView,覆蓋它的-touchesBegan:withEvent:方法,然後創建一個標準的UIViewController,將你的新子類添加到視圖層次結構中。

+0

@Ben:我很確定這個類是一個UIViewController(編輯我的帖子來添加此類的@interface的代碼)。雖然,我添加了UITableView與接口生成器(不是編程),也許這可能是問題? – Goles 2010-02-23 11:18:44

+0

如果它是UIViewController,那麼只需將UITableView替換爲覆蓋-touchesBegan:withEvent:的UITableView的自定義子類即可。 – 2010-02-23 14:19:33