我无法弄清楚这有什么问题。我正在尝试向当前视图添加子视图。我alloc和initWithNibName我的SecondViewController并设置它的myImageView参数是 a UIImageView。问题是添加子视图时myImageView未设置。
这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
SecondViewController *secondView = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
secondView.myImageView.image = [UIImage imageNamed:@"image1.png"];
[self.view addSubview secondView.view];
}
如果我myImageView通过 Interface Builder 将图像设置为正确显示,addSubview但如果我按上述方式设置属性,则它不起作用...UIImageView插座在 IB 上正确连接。
这是SecondViewController:
@interface SecondViewController : UIViewController
{
}
@property(nonatomic,strong)IBOutlet UIImageView *myImageView;
@end