UITextView keyboard hidding problem - iphone

I want to hide the keyboard after typing the content into the UITextView but i can not do this by default like UITextField. Is there any way to hide the keyboard, Rightnow i put the button which can help me out.If any default way to hide it then please tell me.

Use following code for hide the keyboard from text view when user enter "\n"(new line) means press "Done" or "return" button.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:#"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
Example1 and Example2.

[textView resignFirstResponder];
Here is your detail answer

Related

Dismiss keyboard for UITextView without using Return key

I'm using a UITextView and want to keep the normal usage of Return key, i.e. to insert a new line. But how do I dismiss the keyboard when I can't use the Return key for that?
A lot of people add a UIToolbar with a Done button on it above the keyboard. This is how the Safari app does it as well and in my opinion it is the best way to handle this situation. See a pic here.
To dismiss the keyboard, you just have to do [textField resignFirstResponder];.
Here is an okay example of how to add the UIToolbar when the keyboard shows/hides.
How the user triggers it is a design decision: another button, a swipe gesture?
When it's triggered, call:
[self.textView resignFirstResponder];
You could just use a background tap to hide the keyboard.
A good way to Dismiss keyboard.
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
//NSLog(#"ShouldBeginEditing");
if(textView == indexOneTW)
{
here use uibutton and set its target to a method which contains
[urTextView resignFirstResponder]
}
return TRUE;
}
Make sure you declare support for the UITextViewDelegate protocol.
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText: (NSString *)text
{
if([text isEqualToString:#"\n"])
{
[textView resignFirstResponder];
return NO;
}
return YES;
}
Enjoy Buddy with this code....

Using the 'Done' button as the return key

I would like to know if it would be possible to use the 'Done' key of the keyboard as the return key ?
Example :
You are in a search field, you type whatever you want to search for and then instead of tapping on the return key of the keyboard, I would like the user to be able to start the search by tapping on the 'Done' key juste above the keyboard.
Update :
I don't want to change the text or the aspect of the return key. I want to launch the search with the 'Done' blue button that is in the small bar above the keyboard, next to 'Previous' and 'Next'
I just implement the following method:
from UITextFieldDelegate
textFieldShouldReturn:
Asks the delegate if the text field should process the pressing of the return button.
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
Try this :
It will help you...
First set delegate to your all textfields than write this method:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:#"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
textField.returnKeyType=UIReturnKeyDone;
Add this to your text field's delegate to remove the keyboard when it's pressed:
- (BOOL)textFieldShouldReturn:(UITextField *)aTextfield {
[textField resignFirstResponder];
return YES;
}

How can I perform a selector when the user hits the Send button on the iPhone keyboard?

I have a UITextView. When the user hits the Send key I want to be able to automatically perform a selector. How can I do this? I know UITextField has
- (BOOL)textFieldShouldReturn:(UITextField *)textField
Try this out:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text; {
// Any new character added is passed in as the "text" parameter.
if ([text isEqualToString:#"\n"]) {
// If the Done button was pressed, resign the keyboard.
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added.
return NO;
}
// For any other character return TRUE so that the text gets added to the view.
return YES;
}
Hope that Helps!
you can use
[self performSelector:#selector(aMethod) withObject:nil afterDelay:0.1];
in
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
return YES;
}
Hope it helps you..

How to Hide keyBoard on return button itself in TextView in iPhone sdk?

In my iPhone App I am using the control UItextView,
I want to hide the keyBoard on "return" Button itself, I am not using any toolBar,NavigationBar and I don't want to import any other control like button on that View.
What shold I do to hide keyboard ?
Please Help and Suggest,
Thanks
You can use the shouldChangeTextInRange delegate and look for a line break:
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)string
{
if([string isEqualToString:#"\n"]){
[textView resignFirstResponder];
}
return YES;
}

iPhone: Resign Keyboard with Done button action with XIB

hi i am working on UITextview
how to Resign Keyboard, after keyboard "Done button" click Action, which XIB
Thank you
hi if you want answer for, Resign the keyboard of UITextview with default "Done" button on keyboard, then this is answer for that
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text {
// Any new character added is passed in as the "text" parameter
if([text isEqualToString:#"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return NO;
}
// For any other character return TRUE so that the text gets added to the view
return YES;
}
i followed this to resign keyboard of UITextview, if there is any concern inform me
Thank You
Create an IBAction and in IB hook it up to the UITextfield's DidEndOnExit event. Then call the [textViewName resignFirstResponder] to make the keyboard go away.
Alternatively, try using [self.view endEditing:YES] in the IBAction.
To assign the action to the Done button of a keyboard:
In these examples, myTextView is a UITextView that is defined in the header and connected in Interface Builder.
-(BOOL)textViewShouldReturn:(UITextView*)textView {
if (textView == myTextView) {
[textView resignFirstResponder];
}
return YES;
}
To assign it to an external button:
Be sure to define an IBAction in your header, then in Interface Builder, connect the button to this action for touchUpInside:
.h
-(IBAction)dismissKeyboard:(id)sender;
.m
-(IBAction)dismissKeyboard:(id)sender {
[myTextView resignFirstResponder];
}
Call resignFirstResponder on the textview that has focus in order to dismiss the keyboard.