2013-12-21 120 views
-1

当我触摸一个名为tv_Name的文本字段时,它会调出键盘,但当我在键盘外部触摸时,程序崩溃。当我在键盘外部触摸时,IOS程序崩溃

ViewController.h,我已经从而宣告它:

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

并且这是在ViewController.m隐藏小键盘的代码:

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

的代码正上方抛出异常:

** 2013-12-21 13:09:36.027 HerdProfile [818:70b] - [HerdProfileViewController tv_Name:]:u无法识别的选择器发送到实例0x10901ce90 (lldb)**

+0

您可以粘贴详细的代码吗? – jailani

+1

self.tv_Name.delegate = self; – Nico

+0

@nico,我是新来的ios和目标c,我应该在哪里放这段代码? – lost

回答

0

以下对我来说似乎工作正常。

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

你确定你有你的UITextField正确挂接到控制器?如果连接正确,请在@property旁边有一个圆点(请参阅屏幕截图)