2013-06-18 73 views
0

在我的課堂上,我有更多的30個UITextField和一個UIButton。當我點擊uibutton時,我需要退出所有uitextfield的鍵盤,而不給resignfirstresponder所有30個uitextfields。不止一個UITextField鍵盤忽略UIButton點擊iOS

我喜歡這個

-(IBAction)click:(id)sender 
{ 
    [txt1 resignFirstResponder]; 
    [txt2 resignFirstResponder]; 
    [txt3 resignFirstResponder]; 
    [txt4 resignFirstResponder]; 
    . 
    . 
    . 
    [txt30 resignFirstResponder]; 
} 

代碼,我需要簡單的方法,然後辭職的UITextField鍵盤

回答

3
UITextField *currentTextField; 


- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
     currentTextField = textField; 
} 

-(IBAction)click:(id)sender 
{ 
     [currentTextField resignFirstResponder]; 
} 
0

只需在下面的方法添加

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
     [textField resignFirstResponder]; 
     return YES; 
} 

的委託方法

-(void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    [textField resignFirstResponder]; 
} 
7

每一個觀點endEditing財產,儘量簡單,就是

[[self view] endEditing:YES]; 

,讓我知道它是否適合你或不..

0
-(void)KeyboardHide 
{ 
    [txt1 resignFirstResponder]; 
    .... 
    .... 
    [txt30 resignFirstResponder]; 
} 


-(IBAction)click:(id)sender 
{ 
    [Self KeyboardHide]; 
} 
+2

這正是他不願做。另外,沒有這樣的關鍵字「Self」,大寫字母爲S. Plus,用大寫字母開頭的方法名稱並不常見。如果我是你,我會刪除帖子... –