2013-05-28 41 views
-1

我有一個UITextField,我在其中調用以下動畫代碼。它運行良好,但是當我按下返回鍵時,此代碼運行。我希望此代碼在用戶在文本字段中輸入任何數據而不按回車鍵後自動運行。如何在iOS中編輯後調用UITextField上的方法

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
     { 
     [patientNameTextField resignFirstResponder]; 
[addressTextField resignFirstResponder]; 
     [doctortTextField resignFirstResponder]; 
    [self showAnimationBack]; 
     return YES; 
    } 

回答

3

輸入任何數據後意味着你可以使用這個方法。

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ 
//do something here 
return YES; 
} 

或使用這些方法。

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;   // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end 
- (void)textFieldDidEndEditing:(UITextField *)textField;    // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called 
1

嘗試這些委託方法:

- (void)textFieldDidBeginEditing:(UITextField *)textField 
- (void)textFieldDidEndEditing:(UITextField *)textField; 
+0

這種方法將被調用,而編輯的開始,我想,當用戶停止或finshes編輯 –

+0

你怎麼可以決定用戶停止編輯調用此方法?所以我們假設當用戶點擊返回鍵時,這個下面的代表將被稱爲 - (BOOL)textFieldShouldReturn:(UITextField *)textField; 其次,當用戶在文本框中輸入完成,然後點擊屏幕上的任意位置時,將調用以下方法。 - (void)textFieldDidEndEditing:(UITextField *)textField; – Khawar

0

使用

- (void)textFieldDidEndEditing:(UITextField *)textField; 
{ 

[patientNameTextField resignFirstResponder]; 
[addressTextField resignFirstResponder]; 
[doctortTextField resignFirstResponder]; 
[self showAnimationBack]; 

} 
+0

此方法將在編輯開始時調用,我希望此方法在用戶停止或接近編輯時調用 –

+0

我已更改方法名稱 –

2

使用的UITextField的委託方法:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; 

這個方法將每個字符在你輸入文本框後調用。

return YES; 

用於實現您在此方法中所做的更改。 否則

return NO; 
相關問題