ios Xcode 6 错误:Interface Builder 文件中的未知类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24924966/
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-08-31 01:31:43  来源:igfitidea点击:

Xcode 6 Bug: Unknown class in Interface Builder file

iosxcodexcode6interface-builderuistoryboard

提问by Epic Byte

I upgraded to Xcode 6 beta 4 and now my App continuously crashes with the message

我升级到 Xcode 6 beta 4,现在我的应用程序不断崩溃并显示消息

Unknown class X in Interface Builder file.

Interface Builder 文件中的未知类 X。

It crashes because supposedly Xcode can't find my custom classes that I have linked in my Storyboard but it shows that they are linked correctly in the Xcode interface.

它崩溃是因为 Xcode 可能找不到我在 Storyboard 中链接的自定义类,但它显示它们在 Xcode 界面中正确链接。

I'm positive everything is linked correctly. My only other option may be to delete the entire storyboard file and start from scratch because it might be corrupted somehow.

我很肯定一切都正确链接。我唯一的其他选择可能是删除整个故事板文件并从头开始,因为它可能以某种方式损坏。

Edit: I would also like to add that I tried cleaning, reseting simulator, messing with build phases etc. None of that works.

编辑:我还想补充一点,我尝试过清理、重置模拟器、弄乱构建阶段等。这些都不起作用。

回答by Epic Byte

I resolved this issue as I was typing the question. I figured I'd answer my question and leave it here for anyone else who may face this issue when using Xcode 6 beta 4.

我在输入问题时解决了这个问题。我想我会回答我的问题并将其留在这里给其他在使用 Xcode 6 beta 4 时可能遇到此问题的人。

To resolve this issue, you need to select each of your custom class objects in Storyboard (this includes any custom views, even the custom view controllers themselves).

要解决此问题,您需要在 Storyboard 中选择每个自定义类对象(这包括任何自定义视图,甚至自定义视图控制器本身)。

Then with those objects selected, open the identity inspector and under "Custom Class" you should see the Module option. Click inside the Module text box, and press enter.

然后选择这些对象,打开身份检查器,在“自定义类”下,您应该看到模块选项。在 Module 文本框内单击,然后按 Enter。

That's it! The current module for all of my custom objects must have been internally incorrectly set somehow in Xcode 6 beta 4. But there was no visual indication of this in the inspector.

就是这样!在 Xcode 6 beta 4 中,我的所有自定义对象的当前模块必须在内部以某种方式错误地设置。但在检查器中没有视觉指示。

Note that if pressing enter inside the Module text box doesn't work, try selecting the arrow to the right and manually select your current module, then clear the text box and press enter. You can also try pressing enter inside the class text box (although this usually is to resolve a different issue).

请注意,如果在 Module 文本框中按 Enter 不起作用,请尝试选择右侧的箭头并手动选择您当前的模块,然后清除文本框并按 Enter。您也可以尝试在类文本框中按 Enter 键(尽管这通常是为了解决不同的问题)。

Here is an image to make things more clear: enter image description here

这是一张使事情更清楚的图像: 在此处输入图片说明

回答by ChikabuZ

Sometimes Xcode missed customModule="AppName" customModuleProvider="target"

有时 Xcode 会漏掉 customModule="AppName" customModuleProvider="target"

To fix it, open storyboard as source code and replace this line:

要修复它,请打开故事板作为源代码并替换以下行:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass"
sceneMemberID="viewController">

to this:

对此:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass"
 customModule="AppName" customModuleProvider="target" sceneMemberID="viewController">

回答by user1760527

I had this problem after renaming a swift class. Solved it by using the @objc directive:

重命名一个 swift 类后我遇到了这个问题。使用@objc 指令解决了这个问题:

@objc(ForumTopicListViewController) class ForumTopicListViewController

回答by Muhammad Nayab

Project with Multiple Targets

具有多个目标的项目

In my case I am working on Project with multiple Targets and the issue was "inherit from Target" was unchecked. Selecting "inherit from target" solved my problem

就我而言,我正在处理具有多个目标的项目,并且未选中“从目标继承”问题。选择“从目标继承”解决了我的问题

enter image description here

在此处输入图片说明

回答by mavericks

This worked for me..

这对我有用..

Check your compiled source, whether that file(e.g; ViewController.m) is added or not, in my case ViewController file was not added so it was giving me the error..

检查您的编译源,是否添加了该文件(例如;ViewController.m),在我的情况下未添加 ViewController 文件,因此它给了我错误..

enter image description here

在此处输入图片说明

回答by jovanjovanovic

This can happen in any Xcode above 6.0. It happened to me after renaming some ViewController classes in Swift project (but I guess it will happen with Obj-C too). You just have to open the interface builder, go to Identity Inspector of ViewController that had its class renamed, select class and press Enter. That will reassign renamed class to selected ViewController and also reset Module Value which gets lost after renaming the class.

这可能发生在 6.0 以上的任何 Xcode 中。在 Swift 项目中重命名了一些 ViewController 类后,它发生在我身上(但我猜它也会发生在 Obj-C 上)。您只需要打开界面构建器,转到重命名类的 ViewController 的 Identity Inspector,选择类并按 Enter。这会将重命名的类重新分配给选定的 ViewController,并重置重命名类后丢失的模块值。

Update for Xcode 8.1 (probably 8.0 too):

Xcode 8.1 更新(也可能是 8.0):

Xcode 8.1 just crashes. Simply and annoyingly just crashes and doesn't print anything. I was chasing that phantom crash for an hour just to find out that it was this very same thing - unassigned class in IB. If you're getting some phantom crashes, double check IB for unassigned classes first.

Xcode 8.1 刚刚崩溃。简单而烦人的只是崩溃并且不打印任何内容。我追了一个小时的幻象崩溃只是为了发现它是同一件事-IB中未分配的课程。如果您遇到一些幻像崩溃,请先仔细检查 IB 是否有未分配的类。

回答by Arnab

Enabling Inherit Module From Targettook the correct target module. That solved the issue.

启用Inherit Module From Target采用了正确的目标模块。那解决了这个问题。

enter image description here

在此处输入图片说明

回答by Furqan Khan

Sometimes the controller you are providing loses its target membership from the current application. In that case, pressing enter on the "Module" field will do nothing. Go to the controller and make sure that it has target membership set to the current app.

有时,您提供的控制器会失去当前应用程序的目标成员资格。在这种情况下,在“模块”字段上按 Enter 键将不起作用。转到控制器并确保它已将目标成员资格设置为当前应用程序。

回答by Tamara

My answer: set custom Module equal to the custom Pod name (in my example - custom class name) like on the screenshot attached

我的回答:设置自定义模块等于自定义 Pod 名称(在我的示例中 - 自定义类名称),如所附屏幕截图所示

This solution is for a specific case: for custom viewsclasses from Pod(or Carthage) framework.

此解决方案适用于特定情况:用于Pod(或Carthage)框架中的自定义视图类。

Infrastructure: XCode8, Swift3

基础设施:XCode8、Swift3

enter image description here

在此处输入图片说明

回答by Orlin Georgiev

I fixed it by doing exactly the opposite of what ChikabuZ suggested (thanks for pointing it out, though). In the storyboard file, find this:

我通过与 ChikabuZ 建议的完全相反的方式修复了它(不过,感谢您指出这一点)。在故事板文件中,找到以下内容:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass" customModule="AppName" customModuleProvider="target" sceneMemberID="viewController">

and replace it with this:

并将其替换为:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass" sceneMemberID="viewController">

I can't believe how many hours I'm losing getting around bugs in the Swift compiler and Xcode 6

我简直不敢相信我在 Swift 编译器和 Xcode 6 中浪费了多少时间来解决错误