Iphone 如何在我的UIView中正确检测触摸?
我有个问题。我有一个UIView,看起来像这样: 在该视图控制器中,我实现了“touchesbreated:withEvent:”方法,但该方法仅在我触摸视图底部的条时被触发,而在我触摸表格时不会发生任何事情 我怎样才能改变这种行为,以便能够检测到桌子上发生的触摸 这是基本上声明UIViewController的代码:Iphone 如何在我的UIView中正确检测触摸?,iphone,cocoa-touch,uiview,uiviewcontroller,Iphone,Cocoa Touch,Uiview,Uiviewcontroller,我有个问题。我有一个UIView,看起来像这样: 在该视图控制器中,我实现了“touchesbreated:withEvent:”方法,但该方法仅在我触摸视图底部的条时被触发,而在我触摸表格时不会发生任何事情 我怎样才能改变这种行为,以便能够检测到桌子上发生的触摸 这是基本上声明UIViewController的代码: #import <Foundation/Foundation.h> #import <QuartzCore/QuartzCore.h> @interf
#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
#导入
#进口
@界面TripSearchDetailViewController:UIViewController
{
//此子视图的父视图。
UIViewController*父控制器;
//GUI元素
UITableView*表格视图;
UIButton*后退按钮;
}
//按钮动作
-(iAction)goBack:(id)发送方;
-(iAction)showDatePicker:(id)发送方;
//类方法。
-(无效)当前日期选择器;
@属性(非原子,保留)UIViewController*parentController;
@属性(非原子,保留)IBUITableView*tableView;
@属性(非原子,保留)IBUIButton*backButton;
@结束
看起来您使用的是UITableViewController,而不是UIViewController。您的表视图正在拦截和处理触碰,然后再将触碰添加到视图控制器。您需要对UITableView进行子类化,覆盖它的-touchesBegind:withEvent:method,然后创建一个标准UIViewController,将您的新子类添加到视图层次结构中。我认为它可能有助于在TripSearchDetailViewController中实现方法hitTest:withEvent:。如果你只是在这个方法中返回true,你的触摸应该被识别。
另请参见:@Ben:我非常确定这个类是一个UIViewController(编辑我的帖子以添加这个类的@interface的代码)。虽然,我添加了带有接口生成器的UITableView(不是以编程方式),但这可能是问题所在?如果它是UIViewController,那么只需将您的UITableView替换为UITableView的自定义子类,该子类重写-touchesBegind:with事件:。