[英]How to correctly detect touches in my 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
看起来您有一个UITableViewController,而不是UIViewController。 表格视图在将触摸添加到视图控制器之前就对其进行拦截和处理。 您需要子类化UITableView,重写它的-touchesBegan:withEvent:方法,然后创建一个标准UIViewController,以将新的子类添加到视图层次结构中。
我认为这可能有助于在TripSearchDetailViewController中实现方法hitTest:withEvent:。 如果仅以这种方法返回true,则应该识别触摸。 另请参阅: http : //developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.