-1

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)**

staticVoidMan
  • 19,275
  • 6
  • 69
  • 98
lost
  • 81
  • 1
  • 2
  • 8
  • Can you paste your code in detail? – jailani Dec 21 '13 at 08:43
  • 1
    self.tv_Name.delegate = self; – Nico Dec 21 '13 at 08:58
  • @nico, i'm new to ios and objective c, where should i put that piece of code? – lost Dec 21 '13 at 09:07
  • you can put it in viewdidload method. so try there. – Nico Dec 21 '13 at 10:47
  • Have you clear with your problem if not then i will tell you other process to resolve it. – Nico Dec 21 '13 at 10:51
  • 1
    @nico, I fixed the problem. It was to do with wiring the .xib label to the .m file, and then I deleted the method in the .m file only without wiping out the reference in the .xib file. This was causing the crash. Thanks for your help though – lost Dec 21 '13 at 11:29

1 Answers1

0

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)

So Over It
  • 3,668
  • 3
  • 35
  • 46