Call UITextField Editing Did Begin only once - swift

When the user click on the textField i send them to another screen (using Editing did begin) so he can select the option he wants (i use the textfield for design purpose so i cant change this for a button or pickerView or etc)
The question is, when he selects the option he wants i pop this view and send the value back to the textField screen (using delegate).
Now i tried to do textField.resignFirstResponder() but this does not work, since the textField is still selected the action goes into a loop. I can use textField.isDisable but the user can't change the value anymore.
I can fix this by simple putting
if(textField.text != "")
{
return
}
In the textField action. But this is far away from a solution, its more like band-aid on a leak.
And with this if the user select the textField again since i have the if above in the code he will not go to the select screen unless he delete the entire text.
How can i solve this? Since resignFirstResponder its not working. Maybe im doing it wrong?

Please set Delegate for your textfield
textFieldName.delegate = self

Related

is there any possibility to change fields dynamically

Is there any possibility to change the fields like textfield to textview when user click the edit button to change fields.... pls tell me any possibilities
Off the top of my head - dynamically swap to a textview when editing, and when done editing put the text into a textfield and put it back in the view.
Try that and then come back if you have any trouble with coding it.

UITextField becomeFirstResponder works only once

In my app, there is the ability for the user to input their name.
A UITextField is added to the view and becomeFirstResponder is called.
In the textFieldShouldReturn method, resignFirstResponder is called.
Then in textFieldShouldEndEditing, the UITextField is removed from the view.
This all works fine, but the problem is that when the user tries to input their name a second time, the UITextField shows but keyboard does not.
I have tried lots of things, like moving around become/resign firstresponder or retaining/not retaining the textfield, but I just cant seem to get it to work.
Any ideas?
Thanks
If you have a property set for that UITextField, make sure to set it to nil after removing it from the view.
try doing the work in textFieldDidEndEditing, and when you tap on text field second time, control should go in textFieldShouldBeginEditing, try checking that with break points, it it does not goes then problem is that your textfield does not have any memory allocated and if it goes in this function set this textfield as first responder.

iPhone- After resigning first responder on UITextField, can't refocus it

I have a modal window that's used for searching data from a remote server- it has a UITextField as the titleControl of the navbar for the window, and a tableview filling the window (that displays the results obviously). Now what I want to do is when the user scrolls the tableview, immediately have the textfield lose focus (resign first responder) so that the keyboard dismisses and the user has more room to scroll through the tableview (it stretches down to fill the gap left by the keyboard). Basically the same functionality as when using a UISearchDisplayController (or whatever it's called).
So I have this code for detecting the scroll event of the tableview:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[searchField resignFirstResponder];
}
Which works fine. However, the issue is that once the user scrolls the table and the textfield loses focus, you can't give focus back to it by tapping on it again. So basically once I call that [resignFirstResponser] I can never again bring the keyboard back up and edit the textfield value. Anyone have any idea why? Do I need to explicitly call [becomeFirstResponder] on the field somewhere? Because I thought that was handled automatically when the field is tapped?
Also of note- I am calling [becomeFirstResponder] on the text field right when the modal window is first called up, so the field is pre-focused. Could that have anything to do with it?
I can post more code if anyone would like, but I don't think I'm doing anything out of the ordinary with the textfield.
Thanks for any help!
You are calling the resignFirstResponder from a function which will be called everytime you scroll the UIScrollview. Hence it does not appear. You need to call resign when the uitextview goes out of focus.
You can do the following. Its a hack:
Whenever you focus on the UITextField create a invisible button to overlay your scroll view.
Capture the button press event and resign first responder
Whenever the uitextfield becomes first responder create the button
This way you will remove the bug, viz calling the method in scrollViewWillBeginDragging.
Other option would be to overrite viewDidAppear method for the uiTextField.
Or you could put your textfield into a different container and handle scrollViewWillBeginDragging by checking which scrollview sent the message.
Did u set a delegate for you searchField? I had the same issue. I popup a model view, and set the text field to be the first responder inside viewDidLoad. Everything works well for the first time. But once I dismiss the modal view controller, and reopen it. my text field cannot be focused anymore.
I found it has something to do with methods of UITextFieldDelegate. Once I remove implementation for methods
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
everything works well. but don't know why
Are you doing anything with "textFieldShouldEndEditing", like #fengd?
A problem that I had was that I was viewing a modal view, and my "textFieldShouldEndEditing" routine was incorrectly returning "NO" on a specific text field. When my modal got dismissed, I would be unable to tap on any other text-field, presumably because the old text field was still "first responder". Since it can never end editing, it fouls up all other text fields that come after it.
I realize this is 2 yrs after the fact, but maybe someone else might find this useful.

How to keep UIKeyboard when textfield is regisned first responder?

I'm writing an app that has a view similar to the SMS app's text editing view. It has a textview on the top and a textfield on the bottom. I want to allow users to copy and paste texts in the textview while keeping the keyboard appear. But if I try to copy the text, the UITextField will resign first responder and the keyboard will missing. Any ideas about how can the SMS app keep the keyboard while user is copying texts in another view?
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
return NO;
}
I've tried to return NO for -(BOOL)textFieldShouldEndEditing: , but the textview to the upper cannot copy text then.
Related Option:
Just Give a button on Topbar or anywhere else that have option to copy the text then its more user friendly..
Second Option:
If you have much good know programming concepts then just create the new view above the keyboard and animate when keyboard is show and don't resignfirstresponder, and following options are their, copy text, done, in the done action you have resign first responder
Those are only option which u have done if you want more userfriendly app because in appStore and appReview Department have verify the User Convenience UI Integrations and you must full fill that and from the other side user's whom purchase or download the app also give the awesome comments on the app who is more reliable and cashless functionalities ....
I've tried to return NO for -(BOOL)textFieldShouldEndEditing: , but the textview to the upper cannot copy text then.
add a textfield so it can scroll and set the dimentions or just add the scrollbar to scroll it to .. it will solve your problem

Reset UITextField's original placeholder text

I'm adding some user feedback mechanism into my app. The user types some comments into a text field and when that editing is done it updates a UITextView. Then when the user hits the submit button and moves on in the app the user may have need to send more feedback from the same form for a different item. I can reset the other fields and labels in the app to their default values when I hide the view, but not the textField (?). How can I reestablish the placeholder text next time the user accesses this view?
Your suggestions are humbly appreciated.
EDIT:
Thanks to Dwaine. Apparently I had the [textField setText:nil]; in the wrong place. Placing it in my textFieldDidEndEditing worked fine. Also, I was using the Did End on Exit rather than Editing Did End in Interface Builder which screwed things up.
In either the ViewWillAppear or ViewDidAppear (I'd suggest ViewWillAppear) function, set the text value of the UITextField to...nil I think...or just an empty string...
That should make the Placeholder Text show up again I think ^^