-1

我有一个 UITextField 我正在调用下面的动画代码。它运行良好,但是当我按返回键时,此代码运行。我希望此代码在用户在文本字段中输入任何数据而不按返回键后自动运行。

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

4 回答 4

4

输入任何数据后意味着您可以使用此方法。

- (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
于 2013-05-28T04:37:02.707 回答
2

使用 UITextField 的委托方法:

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

此方法将在您在文本字段中输入的每个字符后调用。

return YES;

用于实现您在此方法中所做的更改。别的

return NO;
于 2013-05-28T04:38:24.650 回答
1

试试这些委托方法:

- (void)textFieldDidBeginEditing:(UITextField *)textField
- (void)textFieldDidEndEditing:(UITextField *)textField;
于 2013-05-28T04:34:07.180 回答
0

采用

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

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

}
于 2013-05-28T04:34:27.837 回答