Reputation: 137
How do I save inputed information in multiple uitextfields? and when I switch between viewcontrollers how does the inputed information stay within its uitextfields when switching back and forward? perhaps set within a time frame which then resets itself?
I want the uitextfields to be set automatically without using the "load" function to recall the information back.
Can I see an example in "view controller.swift" thanks.
I am using Xcode 7 - Swift 2.
Upvotes: 0
Views: 145
Reputation: 4065
It depends how you are switching view controllers.
If you are popping, or any other method that destroys the view controller, you will need to store the text from your text fields somewhere else. From what you've written, it seems like you are losing the data.
You should make a class to hold your data, and reference a singleton on that class. You make a class with a singleton like so:
class SomeManager {
var mySavedString: String?
static let sharedInstance = SomeManager()
}
Then in your view controller's viewDidLoad
method, access the information from the singleton class and fill your views with it.
self.myTextField.text = SomeManager.sharedInstance.mySavedString
You can also make the UITextField's delegate your view controller, and then update the saved string whenever the content of the UITextField changes.
@IBAction func textFieldDidChange() {
SomeManager.sharedInstance.mySavedString = self.myTextField.text
}
Upvotes: 1