編輯設置:這個問題是由於缺乏大的理解界面生成器和屬性類是如何工作的。在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