将 initWithNibName 与情节提要一起使用 [英] Use initWithNibName with a storyboard

查看:47
本文介绍了将 initWithNibName 与情节提要一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个在单独的 xib 视图中使用 initWithNibName 的例子:

Below is an example of using initWithNibName with separate xib views:

TerminalViewController *ctrl = [[TerminalViewController alloc]
    initWithNibName:@"ControllerView" bundle:[NSBundle mainBundle]];
ctrl.appDelegate = self;
viewCtrl = ctrl;

但是我需要使用故事板 UI 布局来实现它.对于initWithNibName",我如何指向故事板中的视图:

However i need to implement it with a storyboard UI layout. For 'initWithNibName' how can i point to a View in my storyboard:

即:

    TerminalViewController *ctrl = [[TerminalViewController alloc]     
    initWithNibName:@"STORYBOARD.ControllerView" bundle:[NSBundle mainBundle]];
    ctrl.appDelegate = self;

非常感谢任何帮助.谢谢,戴夫

Any help is much appreciated. Thanks, Dave

推荐答案

你可以在storyboard中给控制器一个Identifier,然后使用这个...

You can give the controller an Identifier in the storyboard and then use this...

[self.storyBoard instantiateViewControllerWithIdentifier:@"TheIdentifier"];

只是为了补充...

从 xib 文件创建 UIViewController 子类时.如果您有一个名为 MyViewController 的类和一个名为 MyViewController.xib 的 xib,那么您需要做的就是...

When creating a UIViewController subclass from a xib file. If you have a class called MyViewController and a xib called MyViewController.xib then all you need to do is...

MyViewController *controller = [[MyViewController alloc] init];

然后系统将查找名为 MyViewController.xib 的 xib 文件,并使用它来初始化对象,并且只有在 xib 文件不存在时才回退到代码中.

The system will then look for a xib file called MyViewController.xib and use that to init the object and only fallback to doing it in code if the xib file doesn't exist.

这篇关于将 initWithNibName 与情节提要一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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