title: Is there an alternative to ViewDidLoad? Any other place to write code which needs to be activated, when a viewController loads?
body: <p>I have a <code>viewController</code> which holds three text fields. Each text field is connected to a label and uses <code>NSUser Default</code> so that when a user writes something in the textfield, the text is saved with a key - and showed in the label assigned to it. That works fine. </p>
  
  <p>Two of the three text field are for the user to write "a question" and an "extra identifier". In case the user don't know what to write in these, in the top of the screen there are two buttons leading to two different <code>tableViewControllers</code> - both of which holds tableViews with inspiration/options that the user can choose. I implemented a segue from each, so that when the user taps a <code>tableViewCell</code>, the text in this cell is passed to the right textfield in <code>viewController1</code> - and the user can now press save and save this text in the <code>NSUser Default</code> and let it be shown in the assigned label. </p>
  
  <p>The problem is that these segues are ofcourse using ViewDidLoad to show the passed text from the inspiration tableViews. This means that when you enter the second tableViewController with inspiration after saving you chosen "question" from the first, then - because of the <code>viewDidLoad</code> method - all textfields and labels are cleared again and only the thing you just passed in there is shown... So: </p>
  
  <p>Can I use another method than <code>viewDidLoad</code> to pass the data into ViewController1?</p>
  
  <p>Or can I maybe add some code to the viewDidLoad method, so that it stops "resetting" all labels and textfields every time you enter the <code>viewController</code>?</p>
  
  <p>Or do I need to go about it all a completely different way?</p>
  
  <p>I hope it all makes sense - sorry about the long explanation! :D</p>
  
  <p>Here's the relevant code from viewController1:</p>
  
  <pre><code>var chosenQuestion:String = ""
  var chosenIdentifier:String = ""
  
  override func viewDidLoad() {
      super.viewDidLoad()
  DiaryQuestionTextField.text = chosenQuestion
  RandomIdentifierTextField.text = chosenIdentifier
  }
  
  
  @IBAction func WriteDiaryName() {
  
      let title = "You have now chosen you diary's name. \n \n Do you wish to save this name and continue? \n \n You can always change all the details."
      let alert =  UIAlertController(title: title, message: nil, preferredStyle: .alert)
  
      alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
  
      alert.addAction(UIAlertAction(title: "Save", style: .default, handler: { action in
          self.defaults.setValue(self.DiaryNameTextField.text, forKey: "DiaryNameKey")
          let NewDiaryName = self.defaults.string(forKey: "DiaryNameKey")
          self.DiaryNameLabel.text = NewDiaryName
  
      }))
          present(alert, animated: true, completion: nil)
      }
  </code></pre>
  
  <p>And there is ofcourse two similar methods for "WriteQuestion" and "WriteExtraIdentifier". </p>
  
  <p>And here's the relevant code from one of the two <code>tableViewControllers</code> with "inspiration":</p>
  
  <pre><code>    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  
      if segue.destination is UpdatingIdentifiers {
          let vc = segue.destination as? UpdatingIdentifiers
          let selectedRowIndex = self.tableView.indexPathForSelectedRow
          let cell = self.tableView.cellForRow(at: selectedRowIndex!)
          let label = cell?.viewWithTag(420) as! UILabel
          vc?.chosenQuestion = label.text!
      }
  }
  </code></pre>
  
  <p>Thanks!</p>
  
  <p><img src="https://i.stack.imgur.com/y0Abw.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/zcYuQ.png" alt="enter image description here"></p>