self.view endEditing is not dismissing the keyboard. Any idea why?

Discussion in 'iOS Programming' started by chrono1081, Jun 1, 2014.

  1. chrono1081, Jun 1, 2014
    Last edited: Jun 1, 2014

    chrono1081 macrumors 604


    Jan 26, 2008
    Isla Nublar
    Hi guys,

    I have a form with a ton of text fields and I'm trying to use:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
        [self.view endEditing:YES];
    To dismiss the keyboard elegantly, however the method is never getting called and I can't figure out why. Even an NSLog statement within the function doesn't print.

    I *think* it has to do with how my hierarchy is set up but I can't say for sure. I can get it to work fine on a blank project but not the one I am currently working in. I have the following view hierarchy (suggested by a UI scrollview tutorial) all of the textfields are in the Content View:


    Could this be the problem? Is there any more information I can provide?

    All of the text fields are in the Content View and the code itself is in the ViewController.m file.

    I already tried asking on Stack Overflow but that site is useless to ask questions on if you're new (and of course the question gets marked as duplicate even though its not and I get pointed to another thread that I already read that is nothing like my issue).

    Any help on this is greatly appreciated.
  2. JohnsonK macrumors regular

    Mar 6, 2014
    The reason the keyboard is not getting dismissed is because UIScrollView will intercept these events, not because endEditing is not working.

    A simple workaround would be setting up a UITapGestureRecognizer and adding it to your UIScrollView.
  3. chrono1081 thread starter macrumors 604


    Jan 26, 2008
    Isla Nublar
    Thanks! I will look into this.

Share This Page