How to clear text fields when tab is changed? - ios

Hello I have a tabbed application.
It's two calculators. However when I change the tab and go back to it, the data that I entered into the text field remains the same. How do I clear it?

Try this for clear textfield add this line in your viewDidUnload or viewWillDisappear method
yourtextfield.text=#"";
Hope this code is useful for you.

Related

iOS why calling removing the first responder from a uitextield affects the keyboard?

Okay i have two urtext fields, when i click on one of them, the keyboard shows.
now i have another button so when the user clicks it, i want to hide the keyboard (okay it is a stupid design, but i am just learning).
when the user clicks that button, what i do in code is calling the resignfirstresponder method on both of the ui text fields like this:
self.firstuitextfield.resignFirstResponder()
self.seconduitextfield.resignFirstResponder()
and by some maject the keyboard disappear, my question is why is that?
I just removed the first responder from them, and that means, according to this question, they will not receive the messages first anymore. How can this make the keyboard disappear? and bty who now becomes the first responder?
Nobody is the first responder! That's what's happening! And if they're no responders, then the keyboard hides! Pretty nifty, right? But if you want one line of code to do this, try self.view.endediting(true), instead.

Text Field doesn't active for Static Cell in Table View Controller?

I have Single View App for IOS Xcode 6.4. Example Add Player screen, I tried it by myself, but Text Field doesn't active to click and typing at my application simulator (UITableViewController Static Cell) I have compared my project with example final project, everything looks good similar. How to fix this problem?
First you try with cmd+k that will open the simulator's keyboard. If that is not working then try with cmd+shit+k that may hide your keyboard but you can able to type on the text filed. If that also not work then you may accidentally off the user interaction for text field. Or may be some other view covering your text field which is transparent, so you are not able to see it. I hope that will save your problem, otherwise please provide your code sample.
There is a bug in the segue transition. Set the transition to None and it should work. I had the problem with a Curl transition.

UITextbox and Navigationcontroller

I'm creating an iOS app with swift and XCode 6. I have a multiple page app with a navigation controller. So far so good. When I enter text in one of the subpages go back to the front and reenter this page the text is gone.
My question to you is how to edit the code, so that the text stays in the text box and does not disappear. I know to somehow create a database but thats all I found so far.
Thank you a lot in advance.
When you go "back" you essentially pop the viewcontroller from the navigationstack. At that point there are no more references to that viewcontroller and it get's deallocated and as a result you loose all your changes.
So if u want to save your text you can store it in NSUserDefaults
NSUserDefaults.standardUserDefaults().setObject(textField.text, forKey:"key")
And in viewDidLoad of specific viewController where you want to populate UItextField fetch it like
textField.text = NSUserDefaults.standardUserDefaults().objectForKey("key") as! String

Keep keyboard always on top & visible

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.

Setting UITextView's editable to NO always resigns FirstResponder. Can be avoided?

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.

Resources