简体   繁体   English

在iOS7中点击UITextFields

[英]Tapping between UITextFields in iOS7

When a UITextField is selected and has a keyboard shown, if I tap other parts of the view the keyboard disappears. 选择UITextField并显示键盘时,如果我点击视图的其他部分,键盘将消失。

If I tap another UITextField , the keyboard stays up, the first textfield is deselected, and nothing happens. 如果我点击另一个UITextField ,键盘保持不动,第一个文本字段被取消选择,没有任何反应。 Then I need to tap on the other UITextFIeld again for selection to happen and a keyboard to appear. 然后我需要再次点击其他UITextFIeld以进行选择并出现键盘。

Is there a way to make a second UITextField immediately accessible when a first UITextField is selected? 有没有办法在选择第一个UITextField时立即访问第二个UITextField?

If you reload the tableview in textFieldDidEndEditing , you'll break selection in this way. 如果你在textFieldDidEndEditing重新加载tableview,你将以这种方式中断选择。 Don't do that. 不要那样做。

try it, press another view should call below fn. 尝试一下,按下另一个视图应该调用fn以下。

-(void)disappearKey{
[self.view endEditing:YES];
}

after keyboard disappear, Tap any textfield, will appear keyboard. 键盘消失后,点击任意文本字段,都会出现键盘。

First of all I think its a bug that the keyboard is not dismissed and opened again when tapping on another UITextField or UITextView. 首先,我认为当点击另一个UITextField或UITextView时,键盘不会被解除并再次打开这个错误。 It should be reported and Apple should fix it. 应该报告,Apple应该修复它。

Using the textfield delegate methods and registering for keyboard notification it should be possible to manually keep track if the user tapped on another textfield and the keyboard did not close and reopen. 使用文本字段委托方法并注册键盘通知,如果用户点击另一个文本字段并且键盘未关闭并重新打开,则应该可以手动跟踪。 At the very least you should be able to detect when this is happening and close the keyboard manually by [textField resignFirstResponder]; 至少你应该能够检测到何时发生这种情况并通过[textField resignFirstResponder]手动关闭键盘;

The keyboard notification are as follows: 键盘通知如下:

UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification

I'm''pretty sure you know the UITextfield and textview delegate methods 我很确定你知道UITextfield和textview委托方法

 – textFieldShouldBeginEditing: 
 – textFieldDidBeginEditing:
 – textFieldShouldEndEditing:
 – textFieldDidEndEditing:

I am not in an active project at the moment so I'm not sure if I just ignored the problem but I can't recall this happening to me. 我目前不是一个活跃的项目所以我不确定我是否只是忽略了这个问题,但我不记得这件事发生在我身上。

  • you can use BSKeyboardControls . 你可以使用BSKeyboardControls just see the demo and decide to use or not. 只是看看演示并决定使用与否。

  • or you can do you have to set tag in sequence to the each textfield 或者您可以按顺序将标记设置为每个文本字段
    in uiview. 在uiview。 then use the below code. 然后使用下面的代码。

     -(BOOL)textFieldShouldReturn:(UITextField*)textField { NSInteger nextTag = textField.tag + 1; UIResponder* nextResponder = [textField.superview viewWithTag:nextTag]; if (nextResponder) { [nextResponder becomeFirstResponder]; } else { [textField resignFirstResponder]; } return NO; } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM