0

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
Mr.Milannist
  • 39
  • 1
  • 10

3 Answers3

2

Hi this is a simple mistake. You have not set the delegate. You can do this by..

- (void)viewDidLoad
{
    [super viewDidLoad];
    textField.delegate = self;
}
rakeshNS
  • 4,227
  • 4
  • 28
  • 42
1

Please add textField.delegate = self; to your viewDidLoad.

Jahm
  • 658
  • 1
  • 12
  • 27
0

Most likely you forgot to set the delegate for textField. Inside your storyboard or nib file, drag your UITextField's delegate to your ViewController.

Infinity
  • 3,695
  • 2
  • 27
  • 35