在UITableView和GoogleMap的视图上开始触摸时closures键盘

我的项目devise:

UINavigationController ---> UITableViewController ---> UIViewController

我在UISeachBar上有一个UISeachBar

我试图使用UITapGestureRecognizer ,它的工作原理,但不是预期的。 当我触摸一个UITableViewCell时,键盘只会解散。

我想让UITableView响应touchesBegan这样我就可以在每次触摸UITableViewCell时使键盘消失,或者只是在表格上滚动。

除此之外,我的UIViewController包含一个googlemap的视图,它确实响应了touchesBegan但只有一个第一个触摸,之后,其他所有触摸都将被忽略。

任何人都可以帮忙吗?

太长了,没有阅读:我想解雇UITableView的虚拟键盘喜欢Safari或铬:当触摸开始,而不是当它结束

尝试像这样创build一个UITableView的子类:

 subclassTB.h #import <UIKit/UIKit.h> @interface subClassTB : UITableView @end subclassTB.m #import "subclassTB.h" @implementation subClassTB - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // do your stuff here //NSLog(@"tap registered"); [super touchesBegan:touches withEvent:event]; } @end 

并在你当前的控制器中使用初始化表

subclassTB *yourtable = [[subclassTB alloc]initWithFrame:youFrame style:yourStyle];

尝试这个

 [self.view endEditing:YES]; 

尝试这个…

添加一个空的图像视图覆盖整个视图(设备的大小),然后添加该图像视图的手势识别器,然后在callback方法中写下面的代码。

 -(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. UIImageView *image;//your IBOutlet imageview UITapGestureRecognizer *recog=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(called:)]; [image addGestureRecognizer:recog]; } -(void)called:(UITapGestureRecognizer *)sender { [[[UIApplication sharedApplication] keyWindow] endEditing:YES]; }