0

I have a ViewController that includes its own .nib file, I am wanting to load another .nib into this ViewController that will be a menu of sorts... however I am just not sure how to do this and was hoping for some help.

Before I show you the code I will explaine what I have done.

  • I have a UIViewController with a Nib that is my main view.
  • I have created another nib which is going to be a menu that appears as a subview to the main view
  • I have changed this nibs class to the UIViewController of the main view so that it can see all of the same IBActions and outlets.
  • I have then run the code below trying to load the seperate nib as a subview however when I run it the subview of the other nib is not showing up....

        jumpBarPortraitNib = [[UIView alloc] initWithFrame:CGRectMake(0.0, 50.0, 320.0, 367.0)];
    
    
    
        // add jumpbar container to view
        [self.view insertSubview:jumpBarPortraitNib belowSubview:actionTabBar];
    
4

2 回答 2

3

这里显然有些混乱。

笔尖只是一个包含(*)对象的存档,包括(通常)一个或多个视图对象(UIView在您的情况下)。您不会“将笔尖加载为子视图”。您实例化 nib,可能将其交给 aUIViewController以拥有和管理它,并将 nib 中引用的视图添加到您的视图层次结构中。

您对第一行代码所做的就是创建一个UIView具有给定帧大小的通用实例,并将其插入到任何 [self view] 中。即使您将视图错误地命名为 nib,您所写的内容也没有实际引用nib

对于您正在做的事情,我可能会走以下两条路线之一:

  1. 在原始 nib 中添加视图作为单独的顶级视图,并将其连接到IBOutlet. UIViewController然后,您可以从设置为 nib 文件所有者的公共实例中轻松显示菜单。
  2. 有一个单独的UIViewController实例来管理菜单视图,你将使用它来实例化笔尖的内容,-initWithNibName:就像@Aaron 提到的那样。(请注意,您不需要在外部设置框架;框架将作为视图的属性存档在 nib 中。)

*:不是真的,但你可以这样想。

于 2012-07-02T22:44:22.740 回答
0

您需要使用 initWithNibName,然后在以下行设置框架:

UIViewController * jumpVC = [[UIViewController alloc] initWithNibName:@"jumpBarPortrait" bundle:nil];
jumpVC.view.frame = //your frame
于 2012-07-02T22:42:26.320 回答