How can I hide the keyboard only for specific UITextFields?
I have a lot of UITextField in a View Controller, which has also a SearchbarDisplayController.
I tried to use this but it blocks the UISearchbarDisplayController's job.
Thank you.
For more detail:
For example I have 3 UITextFields and a searchbar display controller. If there is only UITextFields , while tapping out ofthe keyboard, the keyboard successfully disappear. But when I touch the searchbar, you know the keyboard is open and I enter some text to searchbar. So it gives me some results in searchresultstable of the searchbar. But I can't select any row from searchresultstable. Because the disapper keyboard blocks it.
it seems to me that in this tutorial this method has not been implemented, try to add it
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
}
Related
Editable textfield cells Tableview is causing problem on keyboard tab button everytime it is calling textfieldshouldbeginediting even if i am in first textfield it is not going to nextfield.
It is going to last textfield and if popover is availabe it will crash.How can i fix this so that if enter tab then it has to resign current responder in textfielddidendediting and it should not go to textfieldshouldbegin editing.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
PickerViewController *selectOperatorController;
NSLog(#"tag %d",textField.tag);
return NO;
}
I also declared textfield delegates like didendediting and shouldendediting
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
activeField = nil;
if (self.chooseOperatorController) {
[self.chooseOperatorController dismissPopoverAnimated:YES];
}
return YES;
}
This is not as issue in iOS 6.But it is in iOS 7.
textfieldshouldbegin editing will not allow desktop keyboard tab button input,it cannot judge to move between the textfields.If we add textfielddidbeginediting we can move the controls,eventhough we have two methods we can move by using keyboard tab.So textfielddidbeginediting is mandatory if we want to move bewtween available textfields.
I have a UItextField in a UIScrollView. I assigned an inputView (a picker) on my UITextField but it doesn't work. When I click on my textfield, I get the keyboard instead of a picker. When I delete the UIScrollView it works well (I get the picker). Do you have any ideas? Thanks.
Edit (more clear): I have a UItextField in a UIScrollView. I call a method that shows a picker. But the method is never called when my textfield is in a scrollview and I get the keyboard. When I delete the UIScrollView, my method (show picker) is called and I get my picker.
In case you are already using the textfield delegate, try ...
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self openCustomPicker:self]; // Call your IBAction method
return NO; // Hide both keyboard and blinking cursor.
}
to prevent the UITextField from showing the keyboard.
I have a UIVIew which is a subview and it contains several UITextFields. One of these textfields (which is for DATE) should not be editable using the keyboard, instead of this I use a PopOver with a Datepicker inside.
I run a method when the UIControlEventEditingDidBegin is reached. This method calls the resignFirstResponder on the DateTextField.
Everything works fine if the DateTextField is the first field to edit, but when another textField is edited and of course shows the keyboard and then try to edit the DateField, the keyboard doesn't hide and everything goes normal but with the Keyboard doing anything.
I have tried to call the method endEditing:YES before the resignFirstResponder but it doesn't work. I have tried to run the endEditing:YES and resignFirstResponder on the didEndEditing text field method but theres no way to get that keyboard out.
here is my method:
- (void)showDatePopOver:(id)sender{
[self.view endEditing:YES];
UITextField *textField = (UITextField *)sender;
[sender resignFirstResponder]; // hide keyboard
/** POP OVER LINES**/
}
You should use the textFieldShouldBeginEditing: delegate method instead of resigning first responder in didBeginEditing:
This will allow editing on ALL BUT the dateTextField text field:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return (![textField isEqual:dateTextField]);
}
You should specify that your view controller is a text view delegate as well like so (in the interface declaration [.h file]):
#interface MyViewController : UIViewController <UITextFieldDelegate>
I have tried this solution to hide keyboard but it doesn't work...
How to hide the keyboard when i press return key in a UITextField?
Many thanks
assuming you are using UITextField, how do you create the textfield? is it by xib? or by code? make sure you implement UITextFieldDelegate in your class
#interface YouClass : UIViewController <UITextFieldDelegate>
if its xib, connect your textField to the file owner's delegate. and also connect your File owner to your IBOutlet UITextField
if its by code. just do
yourTextField.delegate = self;
now implement
-(BOOL)textFieldShouldReturn:(UITextField *)textField
Just resign as first responder in your input text field, when the return key pressed. The keyboard will dismissed automatically.
You need to set the Return button to actual built in function type. In one of my apps I have set it as a "Done" button because when the user has finished they can press this and it will drop the keyboard away. To set this add this to your code in somewhere like the -(void)viewDidLoad; method.
textFieldName.returnKeyType = UIReturnKeyDone;
That should then give you a blue done button on the keyboard that hides it.
I've implemented a UISearch bar with the searching functionality set up, however when I press the "Search" button on the keyboard that shows up nothing happens. How can I get the keyboard to hide when the "Search" button is pressed while keeping the text in the search bar intact (To keep the search results present)?
From Text, Web and Editing Programming Guide for iOS:
To dismiss the keyboard, you call the resignFirstResponder method of the text-based view that is currently the first responder.
So you should do this in your UISearchBarDelegate:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
// Do the search...
}
Swift 4
Make sure you have UISearchBarDelegate defined in your UIViewController
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}