Say I have a messaging app on an iPhone, and every time I send a message clicking the "Send" button, I don't want the keyboard to "hide", I want it to stay where it is. Is there any way to do this? I've tried using textViewShouldEndEditing to adjust it, but even when it returns false, the keyboard still hides. I've also tried using textView.becomeFirstResponder() in the textViewShouldEndEditing function, but I'm not sure where to put it. Please help, thanks!
textView.delegate = self;
-(BOOL)textViewShouldEndEditing:(UITextView *)textView{return No;}
Never mind, I got it! I put the textView.becomeFirstResponder() inside of the send button's IBOutlet instead of the textViewShouldEndEditing function.
Related
In textViewDidBeginEditing I'm doing some check to show Alert. My problem is that both Keyboard and Alert show up same time. I don't want keyboard to show when alert is shown. Is it possible to stop keyboard showing up inside textViewDidBeginEditing when I've to show Alert and once alert is dismissed revert it back to normal?
If not how do we achieve it via any other workaround?
Set the UITextView's isEditable property to false.
Detect for taps on the UITextView (that's what a user will do if he wants to start editing) possibly using a UITapGestureRecognizer and check if the tap coordinates lie within the frame of the UITextView.
At this time, the keyboard will not show. You can make the check you need, and based upon whether the check passes or fails, you can make the keyboard show (set UITextView's isEditbale to true and make it the firstResponder).
Once the user has finished editing, reset the state if you want to repeat the similar action.
Call view.endEditing(true) function in textViewDidBeginEditing and keyboard didn't show. I think it's will work.
I'm working on a custom keyboard for iOS which will have its own search field (similarly implemented by PopKey).
My keyboard's textfield is able to take the focus with becomeFirstResponder and I'm able to give it up by using resignFirstResponder. However after I resign focus, the host app has a difficult time retaking focus despite touching the form. The app's textfield will still show the text cursor blinking.
Any ideas? Thanks
The solution is a hack, as of right now you can't really give the host app its focus back.
Subclass a UITextField and on its delegate implement
textFieldShouldBeginEditing by returning NO.
Add a BOOL property isSelected that gets set to YES in touchesBegan (not to be confused with the default selected property)
In your keyboard's keyPressed method, if searchField.isSelected, manipulate the searchField.text. Else, manipulate textDocumentProxy like normal.
Add a clear button and method that wipes searchField.text and searchField.isSelected, allowing any further keystrokes to return to the textDocumentProxy
Add an animation that replicates the blinking type cursor
I have a custom inputView for a particular textfield, and it works well. However, I cannot discern how to dismiss the view and get the regular keyboard back. (I have a SWAP button right next to the TextField.) I tried setting the textfield's inputView to nil, but that did nothing.
I do not need a full custom keyboard, but I need more than an Accessory view above the keyboard, which is why I am trying this route. I need about 20 custom buttons in addition to the regular keyboard, and I do not like the idea of a huge Accessory view taking up so much space.
I also would rather not require the user to initially install a full custom keyboard before being able to use the app.
Thank you very much for any suggestions.
I think you will probably have to do this:
Call resignFirstResponder on the UITextField
After the animation finishes, set your inputView to nil
Call becomeFirstResponder on the text field
The keyboard animation duration is sent in the userInfo dictionary on the keyboard presentation notifications.
In addition to the accepted answer, you can use reloadInputViews() (and this is less likely to suffer any animation glitches resulting from the resignFirstResponder, becomeFirstResponder calls):
yourTextField.inputView = nil;
yourTextField.reloadInputViews();
Here's more info in the Apple's Docs.
I'm trying to work with a textview but its having odd reactions. The textview is where the user enters their information that will be sent to me. Basically I've designed my interface in interface builder and got it looking correct. I have entered place holder text: "Enter your issue here". When I run the app the textview works correctly, I can delete the pre entered text and compose a message. However I need to place a ui tool bar above the key board so I can give the user a way of canceling input. i've implemented its delegate, UITextViewDelegate and implemented
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{}
which does get fired when I tap the text view. However the textview now does not give me the keyboard! it just sits there awaiting input but never displays the keyboard. I need to use textViewShouldBeginEditing so I can tell when the user touches the text view to activate the text entry and attach the uitoolbar I. If I remove the textViewShouldBeginEditing the text view goes back to responding being tapped. I've tried a good few thing, ensured the right connections are made in interface builder, set the delegates etc, etc but nothing seams to fix this.
Any suggestions are welcome and if any more information is needed let me know.
Many thanks in advance.
Are you returning TRUE in the delegate?
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
//Do your things
return TRUE;
}
you can try this
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(myMethod)
name:UITextFieldTextDidChangeNotification
object:myTextField];
you can use UITextFieldTextDidBeginEditingNotification or UITextFieldTextDidEndEditingNotification
My app basically lets you send a piece of text. When the user taps send, I would like to disable the text view which contains the text so the user can't edit it anymore as the text is being sent. It seems though that setting either enableUserInteraction or editable to NO always resigns the first responder (basically the keyboard is dismissed) which is a behavior I don't want. I want to keep the keyboard displayed. Is there anyway around this? Thanks in advance.
While I don't really understand why you think it's a good idea to keep the keyboard on screen if there's nothing to edit, you can achieve this by having a hidden UITextField and making that first responder.
If the UITextView's delegate method textView:shouldChangeTextInRange:replacementText: returns NO, its contents will not be changed.