问题
When a UITextField
is selected and has a keyboard shown, if I tap other parts of the view the keyboard disappears.
If I tap another UITextField
, the keyboard stays up, the first textfield is deselected, and nothing happens. Then I need to tap on the other UITextFIeld
again for selection to happen and a keyboard to appear.
Is there a way to make a second UITextField immediately accessible when a first UITextField
is selected?
回答1:
If you reload the tableview in textFieldDidEndEditing
, you'll break selection in this way. Don't do that.
回答2:
try it, press another view should call below fn.
-(void)disappearKey{
[self.view endEditing:YES];
}
after keyboard disappear, Tap any textfield, will appear keyboard.
回答3:
First of all I think its a bug that the keyboard is not dismissed and opened again when tapping on another UITextField or UITextView. It should be reported and Apple should fix it.
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];
The keyboard notification are as follows:
UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification
I'm''pretty sure you know the UITextfield and textview delegate methods
– 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.
回答4:
you can use 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. 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; }
来源:https://stackoverflow.com/questions/22002638/tapping-between-uitextfields-in-ios7