问题
In my iPad app I have two textfields. One displays the normal, default textfield and the other should display a picker as its input view.
Problem is, once I use the txt1 which displays default keyboard and then when I touch the 2nd textField the txt1 keyboard is staying visible.
I have also written [txt1 resignFirstResponder]; [txt2 resignFirstResponder]; while displaying the picker.
I have checked the txt1 IBOutlet connection and the delegate assignment, those seem to be correct.
What am I missing?
回答1:
Write the following code :
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == txt1)
{
return YES;
}
else
{
return NO; // Write the code for displaying UIPickerView instead of the Keyboard.
}
}
Hope this might solve your issue......
回答2:
txt2.userInteractionEnabled = NO;
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == txt1)
{
[txt2 resignFirstResponder];
// code for Hide Picker
return YES;
}
else {
// [txt2 resignFirstResponder];
[txt1 resignFirstResponder];
// code for go in picker
return YES;
}
}
for more information
回答3:
You have to implement below method to resign Keyboard......
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
回答4:
Have u implemented this method ??
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
回答5:
In your viewDidLoad method write this,
txt2.inputView = pickerView;
and other resignFirstResponder codes should be placed correctly , by this on Tapping txt2, you will directly get pickerview instead of Keyboard.
回答6:
did you implement the delegates property of UITextFieldDelegates to in the header file, if not do that and check
来源:https://stackoverflow.com/questions/9837652/uitextfield-delegate-not-working