编辑:这个问题是由于对接口生成器和类中的属性如何工作缺乏了解。
为什么我不能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
}
注意:我正在使用界面生成器。我确定一切都很好,因为 self.view 和 self.mySubView addSubview: 工作正常..