Reputation: 4170
In my application I have to fill UITextField
from the value exist in UIPickerView
not through keyboard.
I have 2 UITextFields
. In 1st textfield value is fetched from keyboard, and in 2nd textfield value is fetched from UIPickerView
.
So, on tapping 2nd textfield I want to hide keyboard and show UIPickerView
.
This is what I have done:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[pickerToolBar setHidden:NO];//shows toolbar
[pickerTime setHidden:NO];//shows UIPickerView
[textField resignFirstResponder];
}
but after writing the above code the keyboard does not disappear.
Upvotes: 5
Views: 5611
Reputation: 3202
These answers might work but no one gave you the best answer; You can replace the keyboard view with the uipickerview when the textfield is tapped :)
UITextField *field = [[UITextField alloc] init];
field.inputView = [[UIPickerView alloc] init];
Upvotes: 1
Reputation: 798
If you are populating the UITextField based on the UIPicker, why not simply disable user interaction with the UITextField? You can still put data there and the user will not be able to change it. To force the keyboard to stay hidden however, you can make the UITextField detect when it is touched/changed/etc and then have it resign first responder.
Upvotes: 0
Reputation: 70
Try UITextfield
delegate methods. put the following code in texfield didBeginEditing
method.
[texfield resignfirstresonder];
Then the text field will block editing and keyboard will not appear. Make sure you attached the text field delegate to the file owner.
Upvotes: 2
Reputation: 2218
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
[self.view addGestureRecognizer:gestureRecognizer];
gestureRecognizer.cancelsTouchesInView = NO;
- (void) hideKeyboard
{
[textfieldname1 resignFirstResponder];
[textfieldname2 resignFirstResponder];
}
Upvotes: 1
Reputation: 12780
try with text field editable property as FALSE or user interaction enable property false and add one custom button with same size of your textfield with the button event of opening picker view.
Upvotes: 1
Reputation: 2122
It is not possible to hide the keyboard while the focus is inside the UITextField...
You must put UIPicker at a level where it does not get hidden behind the keyboard, so that it does not become an obstacle for you while selecting the value..
And if you're selecting value from UIPicker then why you need to tap in the UITextField, so if you're not tapping in the UiTextField, the keyboard will not be shown...
Cheers!!!
Upvotes: 1