[英]Can't add UITapGestureRecognizer to UITableViewController Inside a UITabbarController
I have an application which has a UITabBarController and Inside one of its items I have a UITableViewController and I want to add a UITapGestureRecognizer to view of UITableViewController. 我有一个具有UITabBarController的应用程序,在其中一个项目中有一个UITableViewController,我想添加一个UITapGestureRecognizer来查看UITableViewController。
Here comes my code: 这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyBoard:)];
[self.view addGestureRecognizer:tap];
}
- (void)dismissKeyBoard:(id)sender
{
[self.view endEditing:NO];
}
But dismissKeyBoard is never called! 但是从不调用dismissKeyBoard! What should I do? 我该怎么办? and why it is not called? 为什么不叫它?
Without knowing whether you are using Storyboards, which these days most people do, have you dragged touch onto your view? 如今大多数人都在不知道您是否正在使用情节提要,您是否已将触摸拖动到视图上? It's just a secondary measure to confirm all bases are covered. 这只是确认所有基础均已覆盖的辅助措施。
-(void) viewDidLoad{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyBoard:)];
[self.view addGestureRecognizer:tap];
}
resignFirstResponder
is the usual call I make rather than endEditing. resignFirstResponder
是我通常进行的调用,而不是endEditing。
UPDATE Something I have noticed is you are calling "sender" in your dismissKeyboard. 更新我注意到,您在dismissKeyboard中称呼“发送者”。 Drop that. 放下
-(void) dismissKeyboard{//**NO SENDER**, then it should work
[self.textField resignFirstResponder];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.