title: iOS - Passing variable to view controller
body: <p>I have a view with a view controller and when I show this view on screen, I want to be able to pass variables to it from the calling class, so that I can set the values of labels etc.</p>
  
  <p>First, I just tried creating a property for one of the labels, and calling that from the calling class. For example:</p>
  
  <pre><code>SetTeamsViewController *vc = [[SetTeamsViewController alloc] init];
  vc.myLabel.text = self.teamCount;
  [self presentModalViewController:vc animated:YES];
  [vc release];
  </code></pre>
  
  <p>However, this didn't work. So I tried creating a convenience initializer.</p>
  
  <pre><code>SetTeamsViewController *vc = [[SetTeamsViewController alloc] initWithTeamCount:self.teamCount];
  </code></pre>
  
  <p>And then in the <code>SetTeamsViewController</code> I had</p>
  
  <pre><code>- (id)initWithTeamCount:(int)teamCount {
      self = [super initWithNibName:nil bundle:nil];
      if (self) {
          // Custom initialization
          self.teamCountLabel.text = [NSString stringWithFormat:@"%d",teamCount];
      }
      return self;
  }
  </code></pre>
  
  <p>However, this didn't work either. It's just loading whatever value I've given the label in the nib file. I've littered the code with <code>NSLog()</code>s and it is passing the correct variable values around, it's just not setting the label.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>EDIT: I've just tried setting an instance variable in my designated initializer, and then setting the label in viewDidLoad and that works! Is this the best way to do this?</p>
  
  <p>Also, when dismissing this modal view controller, I update the text of a button in the view of the calling ViewController too. However, if I press this button again (to show the modal view again) whilst the other view is animating on screen, the button temporarily has it's original value again (from the nib). Does anyone know why this is?</p>