2013-12-21 47 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旁邊有一個圓點(請參閱屏幕截圖)