Interface Builder 文件中的未知类。Xcode 6 和 Swift

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26817036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:07:53  来源:igfitidea点击:

Unknown class in Interface Builder file. Xcode 6 and Swift

xcodeswiftmoduleios8interface-builder

提问by zeiteisen

I started a vanilla master detail project with swift. If I add a new view controller and set the custom class, then the modules list is empty and it is not possible to choose a module. The error message "Unknown class in Interface Builder file." appears in the console if I run the code. How can I setup the storyboard to know the custom class and module?

我用 swift 开始了一个普通的主细节项目。如果我添加一个新的视图控制器并设置自定义类,则模块列表为空并且无法选择模块。错误消息“接口生成器文件中的未知类”。如果我运行代码,就会出现在控制台中。如何设置故事板以了解自定义类和模块?

How it should be. The two classes from the template are just fine.

应该如何。模板中的两个类都很好。

How it should be

应该如何

and how it is

以及情况如何

Missing module

缺少模块

I have to add customModule="Target_Name" customModuleProvider="target"to the interface builder source code. That is really annoying! open .storyboard as source code

我必须添加customModule="Target_Name" customModuleProvider="target"到界面构建器源代码中。那真的很烦人!打开 .storyboard 作为源代码

Update: If I move the whole project directory to another, e.g. to the desktop it works. Looks like my directory with the name "Repository" is broken. Don't know why :(

更新:如果我将整个项目目录移动到另一个目录,例如移动到桌面,它就可以工作。看起来我的名为“存储库”的目录已损坏。不知道为什么:(

回答by Quanlong

I used to encounter the same issue, I finally found that the StoryBoard's Target Membershiphas been set incorrectly

以前也遇到过同样的问题,最后发现是StoryBoard的Target Membership设置错了

enter image description here.

在此处输入图片说明.

回答by Lexo

I was getting the same problem but I discovered that I had inadvertently assigned a non-existing custom class to the view object managed by my view controller. So in the storyboard document view, I selected the badly configured view object, then in the identity inspector, deleted the bad custom class displayed for it (by backspacing and hitting return). That took care of the problem.

我遇到了同样的问题,但我发现我无意中将一个不存在的自定义类分配给了由我的视图控制器管理的视图对象。因此,在故事板文档视图中,我选择了配置错误的视图对象,然后在身份检查器中,删除了为其显示的错误自定义类(通过退格并按回车键)。这解决了问题。

In my case, the custom class should be assigned to to the view controller, and not the view object managed by the controller.

就我而言,自定义类应该分配给视图控制器,而不是控制器管理的视图对象。

回答by pkamb

I hit a similar issue when I changed the default Xcode project's UIViewControllersubclass to instead be a subclass of UITableViewController. (I made this change in the class source file, nothing to do with Storyboard).

当我将默认 Xcode 项目的UIViewController子类更改为UITableViewController. (我在类源文件中进行了此更改,与 Storyboard 无关)。

I then went and typed my new class name into the IB "Class" field of the default "view" in the Storyboard. It would not autocomplete my class name, and then gave the Unknown class in Interface Builder fileerror when run.

然后,我将我的新班级名称输入到情节提要中默认“视图”的 IB“班级”字段中。它不会自动完成我的类名,然后Unknown class in Interface Builder file在运行时给出错误。

The solution was to delete the default UIViewControllerobject from the Storyboard, then add a new UITableViewController. Then, set that object's Class in IB to be your custom class.

解决方案是UIViewController从 Storyboard 中删除默认对象,然后添加一个新的UITableViewController. 然后,在 IB 中将该对象的类设置为您的自定义类。

It seems like the original question may be hitting this issue, as the first screenshot's class is ...ViewControllerand the second is ...TableViewController.

似乎原始问题可能会遇到这个问题,因为第一个屏幕截图的类是...ViewController,第二个是...TableViewController.

回答by Yossi Tsafar

I've encountered the same issue and got it fixed. Reading this question gave me an idea to check the Identity Inspector further more and I found that the class Module should be inherit from target instead from a Nonemodule as I had.

我遇到了同样的问题并修复了它。阅读这个问题让我None有了进一步检查身份检查器的想法,我发现类 Module 应该继承自目标而不是像我一样从模块继承。

Try checking the Inherit Module From Targetcheckbox and rebuild.

尝试选中Inherit Module From Target复选框并重建。

Hope it can help someone, obviously your problem has been solved since it was published in 2014.

希望它可以帮助某人,显然您的问题自 2014 年发布以来已经解决。