0

The text field data is disappearing when I navigate to the splash screen, and then back again. This is embedded in a navigation controller.

class LogInViewController: UIViewController, UITextFieldDelegate, UIAlertViewDelegate, PFLogInViewControllerDelegate { 

@IBOutlet weak var emailTextField: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()    

    self.emailTextField.delegate = self
}


override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.hidden = false

}

func textFieldShouldReturn(textField: UITextField!) -> Bool {
    self.view.endEditing(true)
    return false
}

I want the entered text of the emailTextField field to reappear once I navigate back to the login page from the splash screen. The splash screen is sent back to the login page by a UIButton via a push segue which is clearing any previous text that was entered.

I need to save the entered text as an object and then load it again after I navigate to the login page from the splash screen.

How would I do that?

rene
  • 41,474
  • 78
  • 114
  • 152
Mike
  • 85
  • 1
  • 9
  • I don't expect, but rather want the entered text of the text field to reappear once I navigate back to the login page from the splash screen. The splash screen is sent back to the login page by a UIButton via a push segue which is clearing any previous text that was entered. I need to save the entered text as an object and then load it again after I navigate to the login page from the splash screen. – Mike Apr 09 '15 at 17:05
  • Your question's been reopened; good luck.. I hope someone can help you. – Lynn Crumbling Apr 09 '15 at 19:38
  • By the way, @Undo noted that [this question is pretty close](http://stackoverflow.com/questions/12230274/how-do-you-save-data-for-two-text-fields-using-nsuserdefaults) to yours. – Lynn Crumbling Apr 09 '15 at 19:45

1 Answers1

2

You will need to pass the text (or object) to the splash screen's view controller before navigating back to it, and then pass it to the login view controller in the the prepareForSegue function.

To do this:

  1. If you're unwinding to the splash screen from a Pushed view, this is the easiest way I've found to save data: Passing Data in Swift

  2. If you're unwinding to the splash screen from a Modally presented view, you should create an Unwind Segue: What are Unwind segues for and how do you use them?

But this is a temporary solution as the text won't be saved to the user's device, so restarting the application will delete the text. You would eventually need to use Core Data or SQLite if you want to save data to the device, or this for a less temporary solution. This is a nice tutorial for Core Data.

Community
  • 1
  • 1
EmirC
  • 161
  • 6