IOS program crashes when I touch outside of keypad

155 Views Asked by At

When I touch on a text field called tv_Name, it brings up the keypad but then, when I touch outside the keypad, the program crashes.

In ViewController.h, I have declared it thus:

@property (weak, nonatomic) IBOutlet UITextField *tv_Name;

and this is the code for hiding keypad in ViewController.m:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.tv_Name resignFirstResponder];
}

The code immediately above throws an exception:

**2013-12-21 13:09:36.027 HerdProfile[818:70b] -[HerdProfileViewController tv_Name:]: unrecognized selector sent to instance 0x10901ce90 (lldb)**

1

There are 1 best solutions below

0
On

The following seems to work ok for me.

ViewController.m

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *tvNameTextField;
@end

@implementation ViewController

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.tvNameTextField resignFirstResponder];
}
@end

enter image description here

Are you sure you have your UITextField hooked up to your controller properly? There should be a little round dot beside your @property if it is connected properly (see screen grab)