in order to recognize if a user jumps from editing one textField to another by just touching another one instead of hitting the return button i implemented a method which gets called with the event "Editing did end".
i read this event also happens when, in this case a textField resignsFirstResponder.
Now whenever the user hase a multiple choice I present a modal View with a picker.
I have the problem whenever there is a multiple choice and the user switches textFields without hitting return this method gets called twice and I don know why!
is it possible that the modalviewcontroller resigns all FirstResponder of the parentView when it gets presented ?
you can say
[myTextField1 resignFirstResponder];
[myTextField2 resignFirstResponder];
[myTextField3 resignFirstResponder];
before presenting your controller.
but i have a feeling there could be a better way to solve this if i can understand your problem clearly.
Related
I've noticed it's possible to trigger actions and to move through text fields using the done/next/return key in the bottom right of the iOS keyboard. Would it be possible to maybe change a view or trigger a segue with that button?
For example, it would be cool to be able to type something into a UITextField, and then just tap "Next" to move onto the next viewController instead of having to use a separate button, or navigation item.
May be a stupid question, but something that I've been wondering if it was possible for a while.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//Next button was pressed
//Push some viewcontroller here
return YES;
}
make sure you set the delegate of the UITextField to self
It is possible. If it's a UITextField, you can implement textFieldShouldReturn:. If it's a UITextView, you implement textView:shouldChangeTextInRange:replacementText:, and look for \n in the replacement text.
In either case, you can then perform a segue, do a navigation or modal push, etc.
I have an issue with some of my views, here is a breif outline of my setup:
Tab Bar Controller
|
--View Controller 1
|
--View Controller 2
|
--View Controller 2
On a certain action, View Controller 1 will display a modal dialogue. Within this dialogue, if the user performs another action, then another modal dialogue is shown, using the first modal dialogue to present the view.
On the 2nd ModalDialog I have a UITextField, however when I attempt to type into the text field, nothing happens. Even though the keyboard is displayed and the textFieldDidBeginEditing method is called. I have setup the UITextFieldDelegate and the nessessary responders, but to no avail.
Does anyone know what would cause this issue?
Many Thanks
I've found that on a number of occasions with changing views and with popovers that text fields haven't focused correctly with symptoms like you describe. On these occasions I end up deferring the becomeFirstResponder call until the animation has finished or the view has loaded - for example in a view controllers viewDidAppear method.
Or, simply delay the call to becomeFirstResponder with an appropriate guestimate of the time it will take for the views to change / animate / etc. ie:
[textField performSelector:#selector(becomeFirstResponder)
withObject:nil
afterDelay:0.3];
I would try to 'chain' the modal dialogs from the view controller if that's possible.
The VC opens the 1st modal dialog
Your 1st modal dialog notifies the VC (using delegation probably).
(Maybe required) Close the 1st modal dialog
The VC opens the 2nd modal dialog
Happiness!
I'm not sure what you mean with "modal dialogue" -- I assume you mean either a modally presented view controller with a UIModalPresentationFormSheet modal presentation style or a UIPopoverController.
Here's my best guess: I'm pretty sure that your "modal dialogue" captures all user interactions (by default). So when pushing the first one, it captures all input focus. When pushing the second one, it's capture conflicts with the previous one and hence the keyboard will not work.
Anyways, both types of "modal dialogues" are not meant to be stacked. Even if it may work technically, I dislike like it form a interaction-design perspective. Instead of trying to fix the bug or work around it, try to rethink you modal dialogue. You may fit everything into a single one. For example by using a navigation controller inside that view, or by replacing the the view or by flipping it's contents... etc.
Hope this helps, Max
If I were you I would consider revising the navigational hierarchy. Modal dialogs are considered bad enough as it is, but incorporating a modal dialog within a modal dialog is user interface suicide. It causes confusion to the user and is very non-traditional. Is there any way you can use the first modal popup and simply exchange the content?
A side note: You mentioned setting up the view as being a UITextViewDelegate. Did you the view as the delegate for the textbox? Are you returning NO or FALSE from - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string?
I have a UIViewController that is a UITextFieldDelegate, and I would like the keyboard for its text field to appear as soon as the user navigates to this view, without having to actually touch the text field. It would also be nice to be able to "dismiss" the entire view when the keyboard is dismissed. I am loading the view from a xib file.
I don't have an ivar in the code for the UITextField as yet. I would guess I need one. At this point I am just relying on the delegate to pop up the keyboard.
(I know its not a UITextViewDelegate, like the tag says, but I am new to stackoverflow and can't create the correct UITextFieldDelegate tag.)
Sounds like you want to use [textField becomeFirstResponder] in viewDidAppear.
I am looking for a way to show my own input view (a UITableView) to enter certain keywords in a UITextView faster than typing them, and also be able to type into this text view the normal way. My solution has a button that causes the keyboard to disappear, revealing the table view underneath it.
Problem is I can't figure out how to make the keyboard go away without resigning first responder, and losing the cursor. Has anyone accomplished this before?
Thanks for any help.
Nope
As far as I know there is no way to do this, and I have searched extensively. Very frustrating that selection and the cursor are restricted to the keyboard.
I could be wrong though. Votes? Suggestions?
You can call becomeFirstResponder on some other thing that you choose. It could be a UIViewController or a UIView. I had a similar problem before, I needed to make my keyboard go away when I was pushing my view controller back to its caller, without knowing which textfield was the first responder. Then, on viewWillAppear of my view controller which I was returning back, I called [self becomeFirstResponder] and the keyboard of the pushed view was gone. Because this made whichever text field was it loose being the first responder.
The scope of this question is IPhone 3.1 sdk (app running in simulator still)
I have a table view that has a cell with a UITextField in that cell. The table view is grouped, and has one section with just a couple fields. Im NOT using IB so backgroundTap is out of the question (as far as i can tell at least). When i click the text field, keyboard shows. Hiding it is still troublesome. Ive pulled the UITextFieldDelegate into the mix to hide the keyboard but the textFieldShouldEndEditing method doesnt seem to fire when the background is tapped (when i mean background, im tapping outside of the grouped table view section). First off, should it?
textFieldShouldReturn fires with no problem and i can resign at this point but shouldnt i be able to resign if focus shifts away from that control?
Any help is much appreciated
-me
Generally you'll only stop editing a field when you:
hit the "Done" or action button on the keyboard
begin editing another field
exit the view
have another button on screen that removes focus
From any of these, you can call -[textField resignFirstResponder] to dismiss the keyboard and call your -textFieldShouldEndEditing: method. There's no reason that just tapping on a non-active part of the screen should dismiss the keyboard.