UITextFieldDelegate != IBAction backgroundTap - iphone

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.

Related

becomeFirstResponder does not show keyboard second time (ios 6 + storyboard)

I have a storyboard, which includes navigation between views. Back and forth, and there is also the possibility to jump all the way to the home screen.
Basically, it works like this:
View 1 shows a simple menu.
View 2 shows input fields and automatically shows the keyboard.
View 3 shows a results table. In this view one can go one step back (to view 2) or back to the home screen (view 1).
The keyboard and everything works perfectly the first time, when the user moves from view 1 to view 2. However, when moving either back from view 3 to view 2, or from view 3 and starting all over again, the keyboard does not show.
In the code, I have becomeFirstResponder in the viewDidAppear method. Also, it will resignFirstResponder when loading view 3. Another interesting fact is that when calling the becomeFirstResponder for the second time, it does return NO (while it returns YES the first time). Also, when returning back to this view the textfields are not possible to select, even though they are userInteractionEnabled.
I am really stuck here, so any help is highly appreciated.
I have seen several similar questions to this one, but not found a solution:
becomeFirstResponder seems to work only 1st time for shake gesture
Adding [myUITextField becomeFirstResponder]; does not bring up keyboard
keyboard not responding to resignFirstResponder
UITextField becomeFirstResponder works only once
I was able to track down the problem in my code. Answering this question myself since it might be helpful to others as well.
My issue was that I didn’t really get the order of events correct. I had a button that would move to the next textfield, and if everything was completed it would move to the next screen. This caused the becomeFirstResponder method to be called and not released (resignFirstResponder) when switching to a new screen.
I guess the main advice I can give (at least what finally worked for me), was to just go through all the becomeFirstResponder and make sure it is released before moving to next screen.

Keyboard not dismissed

I am developing a messaging application that have SMS.app-like UI. Conversation screen has text input field at the bottom which is moved up with keyboard. Tapping on conversation area dismisses keyboard by calling resignFirstResponder method on UITextView that we use.
This usually works fine, but users report a weird bug which I can't reproduce and fix. People say that sometimes onscreen keyboard doesn't go away when they tap on conversation area, though text input field loses input focus. Once the view enters that abnormal state users are able to type with keyboard, but text that is being entered is not visible anywhere. This bug happens in one of conversation views and since then no one text input field in other views doesn't work as expected. The only way to stop this weird behavior is killing application from multitasking bar.
Even more weird thing is that keyboard stays visible while navigating between view controllers in UINavigationController. I noticed two things:
if tap on '<Back' from conversation view controller with active text field and visible keyboard, keyboard goes away on view change.
if tap on '<Back' from conversation view controller with inactive text field and visible keyboard, keyboard doesn't go away on view change.
Anyone else experiencing same problems. Any ideas on what may cause this bug?
If the text field has a delegate, and the delegate is returning NO for textFieldShouldEndEditing, then resignFirstResponder will fail. I don’t know if that’s the issue you are seeing, but something to check.
set that textfield/textview delegate to fileowner.

UITextField keyboard doesn't appear

I have a very simple screen with an UITextField with the default configuration, nothing special.
When I touch the UITextField, the keyboard doesn't pops up.
I haven't any custom control, behavior or anything else, just that, but it doesnt'work.
I've done this in previous apps iPhone/iPad apps already on the AppStore but i can't figure out what's going wrong here.
The UITextField is created in Interface Builder, in the nib file.
I've been doing some research and i added an IBAction in the UIViewController for UItextField TouchDown event and the IBOutlet for the UITexField.
In the first line of the code i added:
[textFild becomeFirstResponder];
That's the default behavior of the UITextField, when you touch it, it becomes the first responder asking the system to show the keyboard.
I debugged it and it runs that line, but the keyboard still doesn't shows up.
Thanks in advance.
Many times your code is right, it's just about the settings of your Xcode or the Simulator.
Try Toggling Keyboard Software in the Simulator
Simulator --> Hardware --> Keyboard --> Toggle Software Keyboard
OR just simply hit Command + K it would do the same thing
One thing you should check is to make sure the containing view (the UIView that contains all the controls), which is the View icon in Interface Builder nib viewer, has User Interaction Enabled checked. If the parent container doesn't have this checked, even if the individual controls do, you will see this behavior.
I already figured out by myself!
I had tha UITextField in a UIViewController that gets presented from another view controller
who responds to motion events, and that previous View Controller was allways the First Responder.
All I had to do was everytime i leave the controller's view in viewWillDisappear:(BOOL)animated, i called [self resignFirstResponder]; and that was all.
I took me a while to find this silly oversight, but make sure that both properties of UITextView: selectable and editable are set to true.
Its a pretty basic thing but make sure your USER INTERACTION and ENABLED are checked in the storyboard editor.

iPhone: how can I activate a text field programmatically (and not wait for the user to touch it)

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.

Is it possible to make the iPhone keyboard invisible / remove it without resigning first responder?

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.