I’m trying to add UIImageView subviews to my viewController.view, with consideration for whether they go above or below an image.
Basically, my viewController has an image of a body. I allow the user to add accessories to the scene, for example a hat. I need to put some of these images above, some below the body view index.
However I’m having trouble figuring out how to add the image behind the body. I figured I could try and create a UIImageView property as a reference point on the viewController and do something like this:
//this is from my menuItem class which has a UIViewController property connecting it to the main scene
[self.viewController.view insertSubview:sprite belowSubview:self.viewController.body];
However this code doesn’t work, as I get the warning "Property body not found on object of type 'UIViewController *'", even though I @property and @synthesize it.
Does anyone know what I’m doing wrong, or have a better design on how to implement this? Thanks
@shubhank:
//.h
@interface ViewController : UIViewController {
UIImageView *body;
}
@property (nonatomic, retain) UIImageView *body;
//.m (in viewDidLoad)
self.body = [[UImageView alloc] initWithFrame:CGRectMake(250, 300, 339, 562)];
self.body.image = [UIImage imageNamed:@"body.png"];
[self.view addSubview:body];
Problem Solved:
Silly issue. I simply needed to forward declare my ViewController class in my MenuItem class, rather than use UIViewController *.
Thanks for your help.