Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,455
4,156
Isla Nublar
Hi guys,

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

Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"Here");
    [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:

DZJ23Ec.png


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.
 
Last edited:

JohnsonK

macrumors regular
Mar 6, 2014
142
0
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.
 

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,455
4,156
Isla Nublar
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.

Thanks! I will look into this.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.