title: How to traverse the class hierarchy through a variable assignment in Cocoa Touch?
body: <p>I have created a UIViewController class called MyViewController with a UIImageView in its XIB file. I then import this class into another class. I make an instance of the class and I change the image in the UIImageView using code:</p>
  
  <pre><code>myViewController.myImageView.image = [UIImage imageNamed:@"myImage.png"];
  </code></pre>
  
  <p>This works swimmingly. My app is essentially an image viewer. I wanted to cache next and previous images by preloading a subview with an image. When I place myViewController into a variable like this:</p>
  
  <pre><code>UIViewController *pager = myViewController;
  </code></pre>
  
  <p>And attempt to use the variable to set the image for the UIImageView like this:</p>
  
  <pre><code>pager.myImageView.image = [UIImage imageNamed:@"myImage.png"];
  </code></pre>
  
  <p>I get an "error: request for member 'myImageView' in something not a structure or union".  I've tried doing it using square brackets:</p>
  
  <pre><code>[[[pager myImageView] setImage:[UIImage imageNamed:@"myImage.png"]];
  </code></pre>
  
  <p>I get "warning 'UIViewController' may not respond to '-myImageView' ". How do I access the hierarchy to get to myImageView? I've used a @class in the header and a #import and I've synthesized the class instance. The only solution I have so far is a hack, by doing this:</p>
  
  <pre><code>UIImageView *pager = myViewController.myImageView;
  pager.image = [UIImage imageNamed:@"myImage.png"];
  </code></pre>
  
  <p>Which doubles the amount of variables I have, one for the UIImageView variable, and one for the UIViewController variable. Thanks in advance to anyone that can help out.</p>