gpt4 book ai didi

ios - 获取 Nib 名称/ Nib 到底是什么?

转载 作者:IT王子 更新时间:2023-10-29 05:43:11 24 4
gpt4 key购买 nike

我正在尝试使用来自 this pre-built page menu pod from github

在说明中,它说:

    var controller : UIViewController = UIViewController(nibName:"controllerNibName", bundle: nil)
controller.title = "SAMPLE TITLE"
controllerArray.append(controller)

这是我的代码:

    var chatAreaCtrl : UIViewController = ChatAreaCtrl(nibName: "ChatAreaCtrl", bundle: nil)
chatAreaCtrl.title = "Chats"
controllerArray.append(chatAreaCtrl)

这让我犯了错误:

    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: ...(loaded)' with name 'ChatAreaCtrl''

我是编程和 Swift 的新手,但我想我没有正确指定 Nib 是什么?

谢谢!

最佳答案

Nibfiles 是用户界面文件的旧名称。它们现在实际上是 .xib 文件(文件扩展名在前一段时间发生了变化。)但是老派开发人员和方法仍然使用术语 nib。

仍然支持 Nib 文件(或 XIB 文件,如果您愿意),但大多数人改用 Storyboard。

如果您在 Xcode 中创建一个用户界面文件并以名称 ChatAreaCtl.xib 保存它,那么您将能够使用您显示的代码对其进行初始化。

与 Storyboard 等效的是在 Storyboard 中创建一个新场景,该场景定义 View Controller 的界面,然后使用 instantiateViewControllerWithIdentifier 创建该 View Controller 的实例(instantiateViewControllerWithIdentifier 是等同于 initWithNibName:bundle: 的 Storyboard。或者我想我应该为 Swift 说 UIViewController(_nibName:bundle:)。仍在使用语法Swift 中的函数模板。)

关于ios - 获取 Nib 名称/ Nib 到底是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32238166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com