我正在(尝试)实现一个主视图 Controller 容器,首先实例化介绍 View Controller ,然后再实例化实际的应用程序 View Controller 。但是我无法让它工作,我觉得我缺少一些非常基本的东西。介绍 View Controller 在 initWithFrame 中加载介绍 View :
使用以下界面:
@interface ViewControllerMain : UIViewController
@property (strong, nonatomic) ViewControllerIntroduction *viewControllerIntroduction;
@end
和下面的实现
@implementation ViewControllerMain
- (void)loadView
{
// Instantiate the view controller for the adventure view
self.viewControllerIntroduction = [ [ [ ViewControllerIntroduction alloc] init ] autorelease ];
}
- (void)viewDidLoad
{
[ super viewDidLoad ];
// Instantiate the view controller for the introduction view
[ self addChildViewController: self.viewControllerIntroduction ];
[ self.view addSubview: self.viewControllerIntroduction.view ];
[ self.viewControllerIntroduction didMoveToParentViewController: self ];
}
@end
当我越过 addSubView 语句时,它会退回到 addChildViewController 语句。
我已经尝试解决这个问题几个小时了,我们将不胜感激。
最佳答案
只有在显式创建 View Controller 的 View (self.view
) 时,才应覆盖 -loadView
方法。删除您的 -loadView
方法并将 self.viewControllerIntroduction
的初始化移动到 -viewDidLoad
。
关于ios - 父 View Controller 调用自身而不是 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14155336/