编辑设置:这个问题是由于缺乏大的理解界面生成器和属性类是如何工作的。在UIViewController的一个子视图
为什么我就不能设置像self.mySubView = anoterhView;
一个可以设置self.view = anotherView;
?
## .h
@interface TestController : UIViewController {
IBOutlet UIView *mySubView;
}
@property (nonatomic, retain) IBOutlet UIView *mySubView;
##.m
@implements TestController
@synthesize mySubView;
- (void)viewDidLoad {
AnotherController *anotherController = [[AnotherController alloc] initWithNibName:nil bundle:nil];
anotherView = anotherController.view;
// if i do
self.view = anotherView;
// result: replaces whole view with anotherView
// if i instead do
self.mySubView = anotherView;
// result: no change at all
// or if i instead do:
[self.mySubView addSubview:anotherView];
// result: mySubView is now displaying anotherView
}
注意:我正在使用interfacebuilder。我敢肯定,一切都迷上了还好吧,因为self.view,并self.mySubView addSubview:工作还好吧..
对不起,我不太清楚。在interfacebuilder中作为selfview的子视图,我有mySubView。它作为一个IBOutlet连接到控制器中设置的属性。就像你可以在标题中看到的一样。 – hfossli 2010-02-04 13:08:40