In my app I have something like this:
- (IBAction)backgroundTouch:(id)sender
{
[businessDescription resignFirstResponder];
[self.view endEditing:YES];
}
I am not sure which of the two lines I use is better so I use both :) It works when the text area is highlighted, and the user presses the background.
But users do not always press the background, and sometimes press on other page elements like the next element they are trying to fill out.
In my screen shot, I have the next element below the text area, and when I click there, the keyboard doesn't get hidden. Could anyone help me hide the keyboard when the user clicks on various page elements, and when the textarea happens not to be highlighted?
Here is my .h file:
@interface PlanBusinessController : UIViewController
@property (weak, nonatomic) IBOutlet UITextView *businessDescription;
- (IBAction)submitBusiness:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *buttonProperty;
@property (weak, nonatomic) IBOutlet UITextField *personName;
@property (weak, nonatomic) IBOutlet UITextField *personEmail;
@property (weak, nonatomic)
IBOutlet UISwitch *privacy;
@property (weak, nonatomic) IBOutlet UISwitch *wantHelp;
- (IBAction)helpToggle:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet
UIButton *test;
@end
and here are my .m declarations:
#import "PlanBusinessController.h"
@interface PlanBusinessController ()
@end
@implementation PlanBusinessController
@synthesize nameLabel;
@synthesize emailLabel;
@synthesize businessDescription;
@synthesize buttonProperty;
@synthesize personName;
@synthesize personEmail;
@synthesize privacy;
@synthesize wantHelp;
@synthesize test;
-(void)touchesBegan:(NSSet*)touches
{
UITouch *touch=[touches anyObject];
UIView *view=touch.view;
if (![view isEqual:businessDescription])
{
//[businessDescription resignFirstReponder];
}
}
- (IBAction)backgroundTouch:(id)sender
{
[businessDescription resignFirstResponder];
[self.view endEditing:YES];
}
Thanks!