title: Why is my object not being passed correctly via segue?
body: <p>Say I have 2 controllers, BarViewController and FooViewController.</p>
  
  <p>FooViewController has an outlet to a UIImageView called imageView:</p>
  
  <pre><code>@property (nonatomic, weak) UIImageView *imageView;
  </code></pre>
  
  <p>BarViewController has an outlet to a UIButton button.
  BarViewController has a segue from this button to FooViewController, called BarToFooSegue (done in storyboard).</p>
  
  <p>When I run the following code, and call NSLog on FooViewController.imageView.image, the result is nil, and my image won't display. Why is this the case?</p>
  
  <pre><code>// code in BarViewController
  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  
      if([segue.identifier isEqualToString:@"BarToFooSegue"]){
          NSURL *photoUrl = @"http://www.randurl.com/someImage"; // assume valid url
          UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:photoUrl]];
          UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  
          [segue.destinationViewController setImageView:imageView];
      }
  }
  </code></pre>
  
  <p>I've tried setting FooViewController.imageView to strong instead of weak, but the problem remains:</p>
  
  <pre><code>@property (nonatomic, strong) UIImageView *imageView;
  </code></pre>
  
  <p>Running my debugger, I notice the imageView in FooViewController is updated correctly inside prepareForSegue: but then gets re-updated a few lines afterwards to some newly allocated imageView with @property image set to nil. I am not sure what part of the control flow is causing this because it happened in lines written in assembly language.</p>
  
  <p>I got my code working by adding a UIImage property to FooViewController:</p>
  
  <pre><code>@property (nonatomic, strong) UIImage *myImage;
  </code></pre>
  
  <p>and changing prepareForSegue: in BarViewController to pass the image instead of the imageView:</p>
  
  <pre><code>// code in BarViewController
  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  
      if([segue.identifier isEqualToString:@"BarToFooSegue"]){
          NSURL *photoUrl = @"http://www.randurl.com/someImage"; // assume valid url
          UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:photoUrl]];
  
          [segue.destinationViewController setMyImage:image];
  }
  </code></pre>
  
  <p>and modifying viewWillAppear: in FooViewController:</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated{
      [self.imageView setImage:self.myImage];
  }
  </code></pre>