I can't figure out what's wrong with this. I am trying to add a sub view to my current view. I alloc
and initWithNibName
my SecondViewController
and set its myImageView
parameter that is a UIImageView
. The problem is that when the subView is added the myImageView
is not set.
This is the code:
- (void)viewDidLoad
{
[super viewDidLoad];
SecondViewController *secondView = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
secondView.myImageView.image = [UIImage imageNamed:@"image1.png"];
[self.view addSubview secondView.view];
}
if I set an image to myImageView
via Interface Builder it is correctly displayed on addSubview
but if I set the property as described above it doesn't work... The UIImageView
outlet is correctly connected on IB.
this is the SecondViewController
:
@interface SecondViewController : UIViewController
{
}
@property(nonatomic,strong)IBOutlet UIImageView *myImageView;
@end