Disable keyboard for UITextView without using back key
I am using UITextView and want to keep normal use of the Return key i.e. insert a new line. But how do I cancel the keyboard if I cannot use the return key to do so?
Many people add a UIToolbar with a button Doneon it above the keyboard. This is how the Safari app does it, and in my opinion, this is the best way to handle this situation. See here .
To undo the keyboard you just have to do [textField resignFirstResponder];.
Here's a good example of how to add a UIToolbar when the keyboard is showing / hiding.
How does the user launch this design decision: another button, with a swipe gesture?
When it starts up, call:
[self.textView resignFirstResponder];
To hide the keyboard, you can simply use the background pointer.
Nice way to disable the 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 have declared 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 Friend with this code ....