uitextfield hide keyboard? - iphone

On the iphone. When I press on the uitextfield I don't want a keyboard to popup.
I want the same behavior, just no keyboard at all. How can I hide/close the keyboard when the user presses the uitextfield?

If you want the exact same behavior, without the keyboard, try
textfield.inputView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

Returning NO to UITextFieldDelegate's - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField should do it.

I think you can use
textfield resignFirstResponder
in delegate method -
(void)textFieldDidBeginEditing:(UITextField *)
textField like this:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == yourTextField){
[yourTextfield resignFirstResponder];
}
}

use this method to dismiss a keyboard touch anywhere in the view
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
or
by clicking on keyboard done button
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

Related

How i dismiss keyboard on tapping search button on keyboard regarding UISearchBar?

I m developing an application in which i adding one control UISearchBar. When i started editing text in UIsearchBar then keypad is animated on the screen. After i completed my complete editing or canceling all text then i will stuck on point of dismissing keypad.
How i dismiss keyboard on tapping search key form UIKeypad?
Also same question for UITextField and UITextView?
Thanks
Make sure the view controller which has the SearchBar implements the SearchBarDelegate and you set the searchBar.delegate to self:
#interface AddressSearchViewController : UIViewController <UISearchBarDelegate>
then implement the following method:
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
This will make the keyboard disappear when you tap the search button on the keyboard or the search bar
For the search bar:
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
And same thing for the text field:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
}
Use this code in ViewDidLoad
-(void) ViewDidLoad
{
[super ........];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(hideKeyboard)];
[self.view addGestureRecognizer:gestureRecognizer];
gestureRecognizer.cancelsTouchesInView = NO;
}
- (void) hideKeyboard
{
[texfieldname1 resignFirstResponder];
[texfieldname2 resignFirstResponder];
}

how can I call a method as I click UITextField?

I want to ask that how can I call a method as I do click(touch for start writing) in iphone UITextField, as like we click UIButton and put method in "addTarget", is there any way for UITextFields ?
implement a UITextFieldDelegate and do whatever you want to do in - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField or - (void)textFieldDidBeginEditing:(UITextField *)textField
You should use the first method if you want to stop the textfield from behaving like a textfield. For example if you want to open the textfield editor in a modal view. You can return NO there if you don't want this behavior.
Edit: Here is the code to call myMethod:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[self myMethod];
return YES;
}
You can set textField's delegate and implement textFieldShouldBeginEditing: method in it - that method will get called when user taps the field and before it goes into editing.
See UITextFieldDelegate reference for more methods available.
[textField addTarget:self action:#selector(myMethod:) forControlEvents:UIControlEventEditingChanged];
-(void) myMethod:(id)sender
{
UITextField* textField = (UITextField *)sender;
}
i think this will help..!!
You can code as,
[YourTextField addTarget:self action:#selector(myMethod:) forControlEvents:UIControlEventEditingDidBegin];
-(void)myMethod
{
[YourTextField resignFirstResponder];
//Do whatever you want
}

How to hide keyboard once UITextView becomes the first responder in iPhone SDK?

In my iPhone App when I click on UITextView keyboard becomes visible
I try to use resignFirstResponder on "textDidEndOnExit" event but the keyboard does not hide.
What should be done to hide the keyboard?
please Help and Suggest,
Thanks.
Here another thread about this topic:
how to hide the keyboard when empty area is touched on iphone
i think this can help you.
I would suggest you to keep a toolbar and inside a button called "Dismiss" just above the keyboard. resign your responder and hide the toolbar when dismiss button is clicked. In the textView textViewShouldBeginEditing show the toolbar. Default hide the toolbar.
If you want your UITextView to not allow carriage returns, and close when the user presses the return key (or Done if you have changed the return key type) then implement the UITextViewDelegate protocol and use something like:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if ([text isEqualToString:#"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
oneway, you can also hide keyboard when touch in view screen
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
if(touch.phase == UITouchPhaseBegan) {
[txtDetail resignFirstResponder];
}
}
Make a UIButton or UiBarButton and assign it a method in which write [textView resignFirstResponder];
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
return NO;
}
return No; wont allow your keyboard to appear.Hope it helps.You will not require any toolbar or something.Give it a try...

Resign keyboard when leaving textfield

Hey, I have created a textfield within two custom cells. One textfield shows the standard keyboard and the other the shows a pickerview when entered. The problem I have is when I move from the keyboard to pickerview textfield without clicking the "return" button on the keyboard, the keyboard doesn't resign. However when I do it using the "return" the keyboard resigns. Am using:
- (void)textFieldDidEndEditing:(UITextField *)myTextField{
[myTextField resignFirstResponder];
}
and can't work out why this isn't working.
Thanks,
William
-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == pickertextfield)
{
[textfield1 resignFirstResponder];
[pickertextfield resignFirstResponder];
}
return YES;
}
Does your view controller adopt <UITextFieldDelegate>? Is it hooked up as the delegate of your text fields?
Try using [self.view endEditing:YES]; before showing the pickerview and see it it helps.

iOS: how to send the keyboard down after typing in textField

I want to send the keyboard down after writing in textField.
How can I do this?
Any help would be appreciated.
Implement the - (BOOL)textFieldShouldReturn:(UITextField *)textField; delegate method and tell the text field to resign it's first responder status.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
STEP-1:
You need to set the delegate of the textField to File's Owner (using interface builder)
or
textField.delegate = self; from the viewController programmatically first
STEP-2:
And you implement the method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
Hope this helps.
- (IBAction)textFieldDoneEditing:(id)sender{
[sender resignFirstResponder];
}
connect this to didEndOnExit action of your textfield