Force keyboard to show up via button (iOS) - ios

I have an UITextView and I don't want check editable option, how can call keyboard via a button?
This code doesn't work for me!
-(IBAction) yourButtonClick
{
[myTextView becomeFirstResponder];
[self.view addSubview:myTextView];
}

From the iPhone Application Programming Guide
However, you can programmatically
display the keyboard for an editable
text view by calling that view’s
becomeFirstResponder method. Calling
this method makes the target view the
first responder and begins the editing
process just as if the user had tapped
on the view.
So to show the keyboard programmatically,
[textView becomeFirstResponder];
However, the keyboard will never show if the textView is not editable.
The purpose of showing the keyboard is to allow editing. I assume you just don't want the keyboard to appear when the user taps the text view. In this case, you can enable editable programmatically when the button is tapped.
-(IBAction) yourButtonClick
{
myText.editable = YES;
[myText becomeFirstResponder];
}
Then in the UITextViewDelegate, disable editable when the user finishes editing.
- (void)textViewDidEndEditing:(UITextView *)textView {
textView.editable = NO;
}

Related

How to set focus not on the UITextView when it is shown?

In some cases when the UITextView in shown, I want it does not show focus and soft keybaord, when user clicks on it, both will show.
But in some other cases, I want the focus and soft keybaord shown when the UITextview is shown.
I know how to show the focus but I don't know how to let UItextview lose focus.
Any help is appreciated. thank you!
-(void)viewWillAppear:(BOOL)animated {
if(isEditMode) {
[self.textView becomeFirstResponder];
} else {
[self.textView resignFirstResponder];
}
.....
}
UITextView is a subclass of UIResponder.
To make text view first responder (get focus) use:
textView.becomeFirstResponder()
To make text view resign first responder (loose focus) use:
textView.resignFirstResponder()

Detect when a user presses the space button

I currently have my keyboard set so the type is Numbers and Punctuation [so users can type in a hypen symbol]. Does anyone know how to detect if the user presses the space bar so I can automatically set the style to a different keyboard type [in my case letters] so I don't have to build a custom keyboard?
Try this code - I am sure that it will detect if a space character is coded in - I have not really tested how well the keyboard switch works. You should also try it out without the resignfirstresponder becomefirstresponder code once the code below is working. Good Luck! (PS your viewCOntroller needs to be declared as a UITextview or textfield Delegate)
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText: (NSString *)text_message {
if ([text_message isEqual:#" "]) {
// Put your code to change the keyboard then refresh the screen.
[textView resignFirstResponder]; //close textview or textfield
[textView setKeyboardType:UIKeyboardTypeDefault];
[textView becomeFirstResponder]; // opens keyboard for textfield or textview
[self.view setNeedsRefresh]; // refresh view
// return NO;
}
return YES; //go back to editing
}

Tapping between UITextFields in iOS7

When a UITextField is selected and has a keyboard shown, if I tap other parts of the view the keyboard disappears.
If I tap another UITextField, the keyboard stays up, the first textfield is deselected, and nothing happens. Then I need to tap on the other UITextFIeld again for selection to happen and a keyboard to appear.
Is there a way to make a second UITextField immediately accessible when a first UITextField is selected?
If you reload the tableview in textFieldDidEndEditing, you'll break selection in this way. Don't do that.
try it, press another view should call below fn.
-(void)disappearKey{
[self.view endEditing:YES];
}
after keyboard disappear, Tap any textfield, will appear keyboard.
First of all I think its a bug that the keyboard is not dismissed and opened again when tapping on another UITextField or UITextView. It should be reported and Apple should fix it.
Using the textfield delegate methods and registering for keyboard notification it should be possible to manually keep track if the user tapped on another textfield and the keyboard did not close and reopen. At the very least you should be able to detect when this is happening and close the keyboard manually by [textField resignFirstResponder];
The keyboard notification are as follows:
UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification
I'm''pretty sure you know the UITextfield and textview delegate methods
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
I am not in an active project at the moment so I'm not sure if I just ignored the problem but I can't recall this happening to me.
you can use BSKeyboardControls. just see the demo and decide to
use or not.
or you can do you have to set tag in sequence to the each textfield
in uiview. then use the below code.
-(BOOL)textFieldShouldReturn:(UITextField*)textField
{
NSInteger nextTag = textField.tag + 1;
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
[nextResponder becomeFirstResponder];
} else {
[textField resignFirstResponder];
}
return NO;
}

dismiss Keyboard not working

Hi, I am not able to dismiss keyboard. I have a scroll view which have UITextFields on a it. I tried using
[self.view endEditing:YES];
And
[self.scrollView endEditing:YES];
I tried using resignFirstResponder on individual textfields but no use.
This issue only occurs when I tap a textfield which I am using as button when taped upon it I use
[textField resignFirstResponder];
but old one don't resign whatever I do like I tried using endEditing before I resigned the button like textfield. So my question is what could be the problem in my scenario and is there any way to forcefully dismiss keyboard?
If you want textField to act as button, use delegates.
textField.delegate=self;
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return NO;
}

iOS hide default keyboard and open custom keyboard

I have an UITextview, when user taps on UITextview i need to hide the default keyboard. For that i have done,
[myTextView setEditable: NO];
So the keyboard is not shown, here i have created an Custom View with UIButton, i need to show this UIView when the user taps on UITextView, for that i have done,
textViewDidBeginEditing{
//Here i have added UIView as subview
}
But this method is not working because of,
[myTextView setEditable: NO];
and i need to close the UIView when user clicks the close button inside the UIView
You should be using resignFirstResponder instead of setting the UITextView to not editable. This will hide the system keyboard.
[myTextView resignFirstResponder];
If you want to use a different view for the keyboard then the system provided one then set inputView on the UITextView to the custom view you want to be used in place of the system keyboard.
myTextView.inputView = myCustomView;
Perhaps using textFieldShouldBeginEditing instead of setEditable: NO works?
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//Here i have added UIView as subview
return NO;
}

Resources