问题描述
我有两个NIB
ParentViewController.xib
ChildViewController.xib
ParentViewController.xib包含一个UIView和一个UIViewController。
ChildViewController.xib包含一个UIButton
ParentViewController.xib contains a UIView and a UIViewController.ChildViewController.xib contains a UIButton
我想让ChildViewController.xib在ParentViewController.xib的UIView中加载
我完成了以下操作:
- 在ParentViewController中为UIView创建了@property
- 在ParentViewController中将文件的所有者连接到UIView
- 在ParentViewController的NIB Name属性中将UIViewController设置为Interface Builder中的ChildViewController
- 设置ChildViewController视图属性到ParentViewController中的UIView
- Created @property for UIView in ParentViewController
- Connected File's Owner to UIView in ParentViewController
- Set UIViewController in ParentViewController's NIB Name property to ChildViewController in Interface Builder
- Set ChildViewController view property to UIView in ParentViewController
我希望这将加载ChildViewController到我的UIView在ParentViewController,但没有运气。
I was hoping this would load ChildViewController into my UIView in ParentViewController but no luck.
我得到了以下警告,这可能是罪魁祸首:
I did get the following warning, which could be the culprit:
'View Controller (Child View)' has both its 'NIB Name' property set and its 'view' outlet connected. This configuration is not supported.
我还在ParentViewController的viewDidLoad()中添加了额外的代码:
I also have added additional code in ParentViewController's viewDidLoad():
- (void)viewDidLoad {
[super viewDidLoad];
ChildViewController *childViewController = [[ChildViewController alloc]initWithNibName:@"ChildViewController" bundle:nil];
childViewController.view = self.myView;
}
为什么ChildViewController没有加载在ParentViewController的UIView? p>
Any thoughts on why ChildViewController does not load in the UIView of ParentViewController?
推荐答案
尝试此
[self.myview addSubview: childViewController.view];
而不是
childViewController.view = self.myView;
这篇关于如何在另一个NIB中的视图中加载NIB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!