如何在另一个NIB中的视图中加载NIB? [英] How to load a NIB inside of a view in another NIB?

查看:84
本文介绍了如何在另一个NIB中的视图中加载NIB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个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中加载

我完成了以下操作:


  1. 在ParentViewController中为UIView创建了@property

  2. 在ParentViewController中将文件的所有者连接到UIView

  3. 在ParentViewController的NIB Name属性中将UIViewController设置为Interface Builder中的ChildViewController

  4. 设置ChildViewController视图属性到ParentViewController中的UIView

  1. Created @property for UIView in ParentViewController
  2. Connected File's Owner to UIView in ParentViewController
  3. Set UIViewController in ParentViewController's NIB Name property to ChildViewController in Interface Builder
  4. 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆