Reputation: 1657
I'm making an app in which the 1st ViewController has 5 textfields where I insert data and then move to next controller. But when I comeback after selecting the first ViewController, the textfield doesn't contain any data. This is done through present view controller. I don't know how to handled it....
Upvotes: 2
Views: 1177
Reputation: 2226
I think we're all having trouble understanding your problem.
From what I've understood, you want to save/access the data that was typed into the textField at a later point: if you move to or from another viewController you want the data to still we saved from when you typed it. Correct? (You should also create a label where the text will be displayed after being added to the textField.)
If this is the case, you should use Core Data/NSUserDefaults for this or Parse.
Either one of the two can help you save the data.
Here is a link for the tutorial on CoreData using Swift 2. However, I would not recommend CoreData. Not sure what your purposes are but this may work perfectly for you!: http://www.raywenderlich.com/115695/getting-started-with-core-data-tutorial
I personally use and would recommend using Parse.
Go to Parse.com, created a new account. Download this project: http://www.robpercival.co.uk/parse-working-on-xcode-7swift-2/ and then look at the docs at this link for how to create and store objects so that when moving to and from different ViewControllers your dad stays there and is saved, no matter if you quit the app or changed ViewControllers!: https://www.parse.com/docs/ios/guide#objects
Let me know if this helped and how I can update the question.
Upvotes: 1
Reputation: 14030
when going back you instantiate a completely new viewcontroller instead of really going back to your old one. that is why the textfields are empty. so instead of
var back = self.storyboard?.instantiateViewControllerWithIdentifier("backController") as! UIViewController self.presentViewController(back, animated: true, completion: nil)
try
presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
Upvotes: 1