I have tried this:
In .h
file :
@interface TouchLabelViewController : UIViewController<UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *aTextField;
-(IBAction)hideKeyboard:(id)sender;
In .m
File :
-(IBAction)hideKeyboard:(id)sender{
[(UITextField*)sender resignFirstResponder];
}
And also tried this.
In .h
file :
- (void)viewDidLoad
{
[super viewDidLoad];
aTextField.delegate = self;
}
@property (strong, nonatomic) IBOutlet UITextField *aTextField;
-(BOOL) textFieldShouldReturn:(UITextField *)textField;
In .m
file:
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[aTextField resignFirstResponder];
return YES;
}
But still whenever I touch return key it does not hide keyboard.
You can take Advantage of these(delegate) methods when you set the delegate to the Textfield.
YOu should Check your delegate whether you have set the delegate to the Textfield
set this In your .h
Class
YourViewController : UIViewController <UITextFieldDelegate>
Now Where you created the TextField set delegate like below
myTextField.delegate = self;
And further do same as you were doing
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
EDIT: In case if you were presenting the Current as UIModalPresentationFormSheet
Presentation modes may keep the keyboard visible when not required.
Default implementation affects UIModalPresentationFormSheet visibility.that's why need to overriding it for hiding keyboard
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}