简体   繁体   English

无法将UITapGestureRecognizer添加到UITabbarController内的UITableViewController

[英]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.

相关问题 无法将UIBarButtonItem添加到UITabBarController内的navigationController - can't add UIBarButtonItem to navigationController inside of UITabBarController UINavigationController里面的UITabBarController里面的UITableViewController - UITableViewController inside UITabBarController inside UINavigationController 在UITabBarController内部使用UITableViewController显示ADBannerView - Display ADBannerView with UITableViewController inside UITabBarController 无法在UITableViewController内加载自定义UITableViewCell - Can't load a custom UITableViewCell inside a UITableViewController 我可以在UITabBarController中添加UITabBarController吗? - Can I add UITabBarController in UITabBarController? 如何将 UITapGestureRecognizer 添加到表视图单元格内的 UILabel? - How can I add a UITapGestureRecognizer to a UILabel inside a table view cell? UITabBarController中的“重用” UITableViewController - “Reuse” UITableViewController in UITabBarController 打开UITableViewController作为UItabbarcontroller的一项 - open UITableViewController as an item of UItabbarcontroller 如何在 UIView 中添加 UITableviewController - How to add UITableviewController inside UIView UITapGestureRecognizer取消了UITableViewController中的didSelectRowAtIndexPath - UITapGestureRecognizer cancels out didSelectRowAtIndexPath in UITableViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM