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:
myViewController.myImageView.image = [UIImage imageNamed:@"myImage.png"];
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:
UIViewController *pager = myViewController;
And attempt to use the variable to set the image for the UIImageView like this:
pager.myImageView.image = [UIImage imageNamed:@"myImage.png"];
I get an "error: request for member 'myImageView' in something not a structure or union". I've tried doing it using square brackets:
[[[pager myImageView] setImage:[UIImage imageNamed:@"myImage.png"]];
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:
UIImageView *pager = myViewController.myImageView;
pager.image = [UIImage imageNamed:@"myImage.png"];
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.