I have a textView for which the submit button gets overlapped by the keyboard, so I am trying to add a listener for when a user taps anywhere else on the screen to get rid of the keyboard.
I am trying to add code like this to my controller:
-(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event
{
[textView resignFirstResponder];
}
but this gives a syntax error that the textView is not declared. But that is confusing because I added the textView to the screen already.
Here is the code:
#import "FeedbackController.h"
@interface FeedbackController ()
@end
@implementation FeedbackController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event
{
[textView resignFirstResponder];
}
- (IBAction)submitFeedback:(id)sender {
NSLog(@"This is a test hello");
}
@end
And here is how the screen looks like:

Any idea how I can try to reference the textView correctly? and how I can make the keyboard disappear when the other parts of the screen are touched?
Thanks!
In your .h file you will need to create an
IBOutletto thetextViewvariable, here is how you create the outlet access view inside a storyboard