Iphone UITextField跳转到上一个
我的视图中有两个UITextField,允许用户以1234AA格式输入zipcodeIphone UITextField跳转到上一个,iphone,ios,uitextfield,Iphone,Ios,Uitextfield,我的视图中有两个UITextField,允许用户以1234AA格式输入zipcode UITextField 1:用于带数字键盘的数字部件 UITextField 2:用于字母(常规键盘) 当用户输入四位数字时,我能够自动跳转到第二个文本字段 我为此定制了此方法: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString
- UITextField 1:用于带数字键盘的数字部件
- UITextField 2:用于字母(常规键盘)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
现在我的问题是,当textfield 2为空时,当用户按下delete键时,是否有一种方法可以自动从textfield 2跳回textfield 1
我无法使其工作,因为当textfield 2为空时,不会调用上述方法
有人知道这样做的方法吗?使用textField.tag来识别您的textField。例如,如果分别为texfield 1和texfield 2指定标记0和1
// You could do this in the textFieldDidBeginEditing method //
If (textField.tag == 0)
{
//Now the first textField must be active//
// do the method you had posted above//
}
If (textField.tag ==1)
{
//Now the second textField must be active//
}
下面的链接提供了检查键盘事件背后的逻辑。或者,您也可以使用NSNotification检查键盘事件
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTextFieldChanged:)name:UITextFieldTextDidChangeNotification
object:searchTextField];
检查堆栈溢出问题,以检测空UITextField上的退格
您还可以使用本教程检测按下的键,检查退格,并将控制权转移回文本字段1。