【发布时间】:2012-08-01 18:19:14
【问题描述】:
我不知道这有什么问题。我正在尝试向当前视图添加子视图。我alloc 和initWithNibName 我的SecondViewController 并设置它的myImageView 参数,即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];
}
如果我通过 Interface Builder 将图像设置为 myImageView,则它会正确显示在 addSubview 上,但如果我按上述方式设置属性,它将不起作用...UIImageViewoutlet 在 IB 上已正确连接.
这是SecondViewController:
@interface SecondViewController : UIViewController
{
}
@property(nonatomic,strong)IBOutlet UIImageView *myImageView;
@end
【问题讨论】:
标签: ios uiview uiimageview addsubview