title: iOS: Updating text labels with NSUserDefault data on different views
body: <p>I have a text label on view 1 and a button. If I click the button, I am brought to view 2 through a modal connection. In this view, I enter a number and press a button. The button saves the number to NSUserDefaults, as well as tries to update the text label on view 1 to reflect this number.</p>
  
  <p>Button's code:</p>
  
  <pre><code>- (IBAction)returnToView1:(UIButton *)sender {
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  defaults setObject:@"myNumber" forKey:@"myKey"];
  [defaults synchronize];
  _myLabel.text = [defaults stringForKey:@"myKey"];
  }
  </code></pre>
  
  <p>However, when I go back to view 1 using a modal connection, the label never updated. I could solve this by adding the following code:</p>
  
  <pre><code>-(void)viewDidAppear:(BOOL)animated
  {
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  _myLabel.text = [defaults stringForKey:@"myKey"];
  }
  </code></pre>
  
  <p>The problem is, view 1 first loads, and then the text field populates, so it looks unprofessional. I want the text label to populate before loading the view. I've tried placing this code inside of this method:</p>
  
  <pre><code>(void)viewWillAppear:(BOOL)animated
  </code></pre>
  
  <p>...but that didn't work either (for some reason the text field would only populate after I closed the app, switched to view 2, pressed the button a second time, and then returned to view 1). Thanks for any suggestions!</p>