I am working on iPad app and for textfield i have some validation like its text cant be empty if so it should display an error alert.But in iPad we have its default button at the bottom right corner of keypad which has image some what like a keyboard.Clicking on this very button the keyboard resigns automatically without any validation check
.
How i can disable the textfield resign clicking on this button.
[textField resignFirstresponder];
or
textfieldsholdreturn method will help ?
I'm not 100% sure about this, but the textFieldShouldEndEditing: method in UITextFieldDelegate protocol should be what you're searching for.
The documentation says:
Note: If you use this method to validate the contents of the text field, you might also want to provide feedback to that effect using an overlay view. For example, you could temporarily display a small icon indicating the text was invalid and needs to be corrected. For more information about adding overlays to text fields, see the methods of UITextField.
Related
Apple's FoodTracker tutorial for writing iOS apps using Xcode and Swift involves a text field and an image picker. The user can enter text into the text field and have the app display that text in a label. Separately, when the app's user clicks on an image that the app displays, an image picker is created to let the user select a different image and have the app display that image.
According to the tutorial, the function that gets called when the user taps on the image needs to call the text field's resignFirstResponder function in order to get rid of the keyboard that is displayed while the text field is being used, but I'm finding that this isn't the case. I can comment out that call to resignFirstResponder, and the keyboard still goes away. Furthermore, if I start using the text field in the app but then tap the image to bring up the image picker, the text field's textFieldDidEndEditing function gets called regardless of whether the image picker's code calls resignFirstResponder on the text field.
Can someone please shed some light on this situation? Personally, I think it makes sense that the image picker code doesn't have to worry about the text field, but Apple's tutorial claims otherwise. Here's a link to the part of the tutorial that claims a call to resignFirstResponder is necessary. You'll see it quickly if you just search for "resignFirstResponder." https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson4.html
You are right. By presenting the new viewcontroller the textfield is no longer in front so it can't be the first responder anymore. But the problem is that it is not that sure that it works then calling .resignFirstResponer. So it is more to make sure that it will work.
I have view with a text field, an image and a few buttons.
I want to make sure the keyboard is displayed and is on top when the view is displayed
AND
I want to make sure it doesn't go away after I type something in to the text field and submit it.
I called [txtField becomeFirstResponder] with viewdidload and the keyboard is appearing by default but with a tiny delay after the view is displayed.
Also the becomefirstresponder doesn't help after I have my text field submitted.
Thanks in advance for your help!
Also the becomefirstresponder doesn't help after I have my text field submitted.
That part makes no sense. By default, a text field does not dismiss the keyboard unless you dismiss it with endEditing: or resignFirstResponder. If the keyboard is going away, you must be making it go away. So don't and it won't.
EDIT: And indeed, your comment later reveals the answer: you've hooked up the didEndOnExit control event from the text field. Well, that causes the keyboard to be dismissed when the user presses the Done button! So you are effectively hitting yourself in the face and then complaining that someone is hitting you in the face.
So the solution, obviously, is don't hook up the didEndOnExit control event (to anything). Instead, just give the text field a delegate and use the delegate messages to learn what the user is doing. None of those have any automatic behavior with regard to the keyboard, so the keyboard won't be dismissed automatically. For example, to learn when the user is typing, use textField:shouldChangeCharactersInRange:replacementString:. To learn when the user has hit the Done button, use textFieldShouldReturn:. And so on.
In Apple's Messages app, if you make a typo, the little correction bubble shows up. Before you hit space, this bubble lets you know that any further activity (spacebar or submit button) without dismissing the bubble will result in the autocorrection.
I have a text submission form in my app - but in my app, when the user tries to submit the textview while the autocorrect bubble is up, the textview will NOT take the autocorrection. How do I make it take the autocorrection and THEN submit?
Screenshot of the autocorrect bubble.
http://imgur.com/tLyJn
You need to call [self.view endEditing:YES] when you "submit" the text view where self is the view controller containing the text view.
The call to endEditing: will ensure the proper chain of events occur resulting in the text view's text being updated properly. This is what I do in my app.
I'm creating an app that uses a custom keyboard, now if I provide the default English keyboard using the same globe icon that iOS uses, it should be able to switch to the default English keyboard fine, but I'm not sure if the user can return back to my custom keyboard from the system keyboards (assuming the user has more than 1 keyboards).
Can someone please confirm if that would be possible?
Thanks
It's not. the system keyboards have no "switch to custom keyboard" button. They're not even aware you made a custom keyboard.
What is it you're trying to accomplish? Why are you building a custom keyboard? If you tell us, maybe we can suggest an alternate way to do what you need to do.
You should set an inputAccessoryView in your UITextView with a button to toggle between your custom and the standard keyboards.
Every time the user taps the button you change myTextView.inputView between your custom keyboard and nil, which restores the original keyboard.
https://developer.apple.com/library/ios/documentation/uikit/reference/UITextField_Class/Reference/UITextField.html#//apple_ref/occ/instp/UITextField/inputView
You'll also need to reassign first responder, and also try to animate it if you want:
Animating UITextInput's textInputView
What you need is making a custom keyboard check this:
App Extension Programming Guide
I can add a small cross button that is used to clear all the text in a single click in a UITextField with the following code.
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
I also implemented UITextFieldDelegate.
I want to activate/deactivate the right bar button of the UINavigationBar according to the changes in my UITextField. The rule is simple: if the text field has at least one character, just enable the button, else disable it.
I implemented the UITextField's delegate method textField:shouldChangeCharactersInRange: to constantly check the requirement and update the status of the button.
Now my problem is, when I click the small cross button on the text field, the method textField:shouldChangeCharactersInRange: is not called. So the required action is missing. How can I identify the hit event of the clear button?
Some pictures to show what I'm talking about.
Initial stage: here, the "Done" button is disabled because there are no letters in the text field
When typing a letter, the "Done" button is enabled
Now, if I click on the clear button, the "Done" button is still enabled. This is wrong.
Use the delegate method textViewShouldClear::
Asks the delegate if the text field’s current contents should be
removed.
- (BOOL)textFieldShouldClear:(UITextField *)textField
Parameters
textField
The text field containing the text.
Return Value
YES if the text field’s contents should be cleared; otherwise, NO.
Discussion
The text field calls this method in response to the user pressing the
built-in clear button. (This button is not shown by default but can be
enabled by changing the value in the clearButtonMode property of the
text field.) This method is also called when editing begins and the
clearsOnBeginEditing property of the text field is set to YES.
Implementation of this method by the delegate is optional. If it is
not present, the text is cleared as if this method had returned YES.
Availability
* Available in iOS 2.0 and later.
Declared In
UITextField.h
You can use textFieldShouldClear: delegate method to handle when user taps on clear button.