我正在尝试使用this pre-built page menu pod from github的pod在我的应用程序中实现一个页面菜单片段
在说明书中,它说:
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是什么?
谢谢!
发布于 2015-08-27 07:44:31
Nibfiles是用户界面文件的旧名称。它们现在实际上是.xib文件(文件扩展名不久前更改了)。但年长的学校开发人员和方法仍然使用术语nib。
仍然支持XIB文件(如果您愿意,也可以支持XIB文件),但大多数人会改用情节提要。
如果您在Xcode中创建了一个用户界面文件,并将其保存为ChatAreaCtl.xib,那么您将能够使用所显示的代码对其进行初始化。
与故事板等效的方法是在定义视图控制器接口的故事板中创建一个新场景,然后使用instantiateViewControllerWithIdentifier创建该视图控制器的实例(instantiateViewControllerWithIdentifier是相当于initWithNibName:bundle:的故事板。或者我想我应该说UIViewController(_nibName:bundle:)代表斯威夫特。仍在使用Swift中函数模板的语法。)
https://stackoverflow.com/questions/32238166
复制相似问题