Hi this is a simple mistake. You have not set the delegate. You can do this by..
- (void)viewDidLoad
{
[super viewDidLoad];
textField.delegate = self;
}
Question
I'm new in iOS Development for iPhone. I can not dismiss keyboard, nothing works. Please help me, maybe I didn't notice anything?
My .h file:
#import "UIKit/UIKit.h"
@interface ViewController : UIViewController <UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textField;
@end
My .m file:
#import "ViewController.h"
#import "UIKit/UIKit.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL) textFieldShouldReturn: (UITextField *) textField{
[textField resignFirstResponder];
return YES;
}
@end
La solution
Hi this is a simple mistake. You have not set the delegate. You can do this by..
- (void)viewDidLoad
{
[super viewDidLoad];
textField.delegate = self;
}
Autres conseils
Please add textField.delegate = self;
to your viewDidLoad
.
Most likely you forgot to set the delegate for textField. Inside your storyboard or nib file, drag your UITextField's delegate to your ViewController.