title: Passing data between ViewControllers in iOS
body: <p>I am trying to pass an integer value between <code>UIViewControllers</code>, new to iOS and having problems.</p>
  
  <p>In the <code>UIViewController</code> where the value is being set, there are no problems. But after the value is set <code>NSLog</code> is showing that the value is null in the second <code>UIViewController</code>.</p>
  
  <p>My app is going to use the horizontal slider to determine the length of time in between a <code>UIImage animationDuration</code> in a different <code>UIViewController</code>.</p>
  
  <p>This method is correctly receiving the value from the horizontal slider. I initialized an instance of the "other" <code>UIViewController</code>, <code>imageview.somedata</code> belongs to the other view controller. I know the value is being passed correctly because of the <code>NSLogs</code> below.</p>
  
  <pre><code>- (IBAction) changeButtonPressed:(id)sender {
  imageView = [[GTImageView alloc] initWithNibName:@"GTImageView" bundle:nil];
  NSLog(@"text value = %@", myTextField);
  NSString *textValue = [myTextField text];
  int value = [textValue floatValue];
  if (value &lt; 0) value = 0;
  if (value &gt; 100) value = 100;
  mySlider.value = value;
  sliderValue = &amp;value;
  NSLog(@"sliderValue = %d", *(sliderValue));
  myTextField.text = [NSString stringWithFormat:@"%.1d", value];
  if ([myTextField canResignFirstResponder]) [myTextField resignFirstResponder];
  imageView.someData = *(sliderValue);
  NSLog(@"imageView.someData = %d", imageView.someData);
  }
  </code></pre>
  
  <p>This is the top of that implementation file</p>
  
  <pre><code>    #import "GTSettingsVC.h"
      #import "GTImageView.h"
      #import "GTImageView.m"
      @interface GTSettingsVC ()
      @end
  
      @implementation GTSettingsVC
      @synthesize mySlider, myTextField;
      @synthesize sliderValue;
  </code></pre>
  
  <p>That header file</p>
  
  <pre><code>    #import "GTImageView.h"
      @interface GTSettingsVC : UIViewController
      {
      IBOutlet UISlider *mySlider;
      IBOutlet UITextField *myTextField;
      GTImageView *imageView;
      int *sliderValue;
      }
  
      @property (nonatomic) int *sliderValue;
  </code></pre>
  
  <p>The header file of the view controller I am trying to send the data to </p>
  
  <pre><code>    #import &lt;UIKit/UIKit.h&gt;
  
      @interface GTImageView : UIViewController
      {
      UIScrollView* scrollView;
       UIPageControl* pageControl;
       int *someData;
       }
       @property (nonatomic) int *someData;
  </code></pre>
  
  <p>The implementation file where I want the variable someData to have the value I gave it in the first controller. NSLog is returning null in this implementation. </p>
  
  <pre><code>    - (void)viewDidLoad
      {
       [super viewDidLoad];
       // Do any additional setup after loading the view from its nib.
  
  
  
        UIImageView *animatedImageView = 
       [[UIImageView alloc] i nitWithFrame:CGRectMake(0,      55, 400, 550)];
        [self.view addSubview:animatedImageView];
  
         animatedImageView.animationImages = [NSArray arrayWithObjects:
                                       [UIImage imageNamed:@"IMG_0052.JPG"],
                                       [UIImage imageNamed:@"IMG_0054.JPG"],
                                       [UIImage imageNamed:@"IMG_0081.JPG"],
                                       nil];
        NSLog(@"some data = %@", someData);
     //   NSLog is returning null
        int x = someData;
        animatedImageView.animationDuration = 
        x * [animatedImageView.animationImages count];
        [animatedImageView startAnimating];
        [self.view addSubview: animatedImageView];
  
        }
  </code></pre>