xcode Interface Builder 文件中的未知类

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

Unknown class in Interface Builder file

iphonexcode

提问by Brett

Why am I still getting this error when I run my iPhone app? The file is a ViewController that I have been working to delete and replace, but it just won't die. As far as I know, I don't have any reference (string or otherwise) to this file in my project.

为什么在运行 iPhone 应用程序时仍然出现此错误?该文件是我一直在努力删除和替换的 ViewController,但它不会消亡。据我所知,我的项目中没有对此文件的任何引用(字符串或其他方式)。

  • I have deleted the related file (I'm trying to get rid of it.)
  • I have cleaned the project and rebuilt.
  • I have "Reset Content and Settings" in my simulator.
  • I have done a grep (grep -i -r "TheClassName" *) and nothing matches except my UserInterfaceState.xcuserstate file.
  • I have searched the code using XCode's Find/Replace tab.
  • I have double checked my Build Phases and am pretty sure it isn't in there (its a large project).
  • 我已经删除了相关文件(我正在尝试摆脱它。)
  • 我已经清理了项目并重建了。
  • 我的模拟器中有“重置内容和设置”。
  • 我已经做了一个 grep (grep -i -r "TheClassName" *) 并且除了我的 UserInterfaceState.xcuserstate 文件之外没有任何匹配。
  • 我已经使用 XCode 的“查找/替换”选项卡搜索了代码。
  • 我已经仔细检查了我的构建阶段,并且很确定它不在那里(这是一个大项目)。

Any other ideas? I've spent way too many hours trying to figure this simple thing out; I must be missing something.

还有其他想法吗?我花了太多时间试图弄清楚这个简单的事情;我肯定错过了什么。

Thanks!

谢谢!

回答by Reid

Check your nibs or storyboard, and make sure none of your views are set to the class!

检查你的笔尖或故事板,并确保你的所有视图都没有设置到类中!

回答by Brett

I finally fixed the problem after trying it on multiple machines over the course of almost 2 days! I will not be thwarted!

我在多台机器上尝试了将近 2 天后终于解决了这个问题!我不会被阻挠的!

I tracked the problem down to a call to setViewControllers on a UINavigationController which is called on initialization of the application. I was always being passed 3 objects (there are 3 panes in the navigation controller). Even though I had deleted the third object, as previously explained, three objects would always be passed in. The class type of the first two was correct, but the third would just be a UIViewController. Curiously, this view controller had a nibName which corresponded to the object file and Xib file that I had previously deleted. Of course, when view was called on this borked UIViewController, it would crash since the corresponding nib had obviously been deleted. Remember, the textual name of this object or Xib could not be found in my directory with grep, so I have absolutely no idea how in the world it came into existence when I ran my app.

我将问题追溯到对 UINavigationController 上的 setViewControllers 的调用,该调用是在应用程序初始化时调用的。我总是被传递 3 个对象(导航控制器中有 3 个窗格)。即使我删除了第三个对象,如前所述,总是会传入三个对象。前两个的类类型是正确的,但第三个只是一个 UIViewController。奇怪的是,这个视图控制器有一个 nibName,它对应于我之前删除的目标文件和 Xib 文件。当然,当在这个 borked UIViewController 上调用 view 时,它会崩溃,因为相应的 nib 显然已经被删除了。请记住,使用 grep 在我的目录中找不到此对象或 Xib 的文本名称,

So, I figured the app may not have been cleaned properly. I double and triple checked this. I even validated that my Workspace settings were correct (File->Project Settings->Advanced). The app was indeed being recompiled fresh every time.

因此,我认为该应用程序可能未正确清理。我两次和三次检查了这个。我什至验证了我的工作区设置是正确的(文件-> 项目设置-> 高级)。该应用程序确实每次都被重新编译。

Secondly, I started thinking that perhaps the object was being set by some other means. Working backwards, I added some breakpoints and found out that initWithCoder was being called on the parent UINavigationController--this was eventually working down to call the setViewControllers on the object and assigning the three view controllers (one of which was the offending one). I could easily see from the call stack that the Nib file that was being loaded was deserializing something offensive.

其次,我开始思考对象可能是通过其他方式设置的。向后工作,我添加了一些断点,发现 initWithCoder 正在父 UINavigationController 上被调用——这最终会调用对象上的 setViewControllers 并分配三个视图控制器(其中一个是有问题的)。我可以很容易地从调用堆栈中看到正在加载的 Nib 文件正在反序列化一些令人反感的东西。

So, I started digging into my Xib file. Of course, the object name wasn't in the file (as expected since the grep didn't find anything). I deleted and recreated the portion of the Xib that included my root UINavigationController. This ended up changing the Object ID and ref within the Xib file. Secondly, I created a new Xib and UIViewController with the same names as the one which I had previously deleted, hoping that Xcode might be happy if I created and then re-deleted them. I then compiled, re-deleted them, updated by Xib file yet again, reverified with grep that yes, indeed, nothing existed with that name.

所以,我开始深入研究我的 Xib 文件。当然,对象名称不在文件中(正如预期的那样,因为 grep 没有找到任何东西)。我删除并重新创建了包含我的根 UINavigationController 的 Xib 部分。这最终更改了 Xib 文件中的对象 ID 和引用。其次,我创建了一个新的 Xib 和 UIViewController,其名称与我之前删除的名称相同,希望如果我创建然后重新删除它们,Xcode 可能会高兴。然后我编译,重新删除它们,再次由 Xib 文件更新,用 grep 重新验证是的,确实,该名称不存在。

And it worked. After spending multiple days on this issues, I'm fairly sure that there is a bug here in the interface builder, but do I want to revisit this problem to file a bug report? Absolutely not...

它奏效了。在这个问题上花了多天之后,我相当确定界面构建器中存在一个错误,但是我想重新访问这个问题以提交错误报告吗?绝对不...

回答by Nirav

In my case, I solved an issue by name of Custom class name of Viewinstead of Custom class of ViewController. By mistake i added like this for view as shown below.

就我而言,我通过名称解决了一个问题,Custom class name of View而不是Custom class of ViewController. 我错误地添加了这样的视图,如下所示。

enter image description here

在此处输入图片说明

It Should be for ViewController like this.

它应该是这样的 ViewController。

enter image description here

在此处输入图片说明

This is in my case, for you may be it's related with another component.

这是在我的情况下,因为您可能与另一个组件有关。

回答by Litehouse

This happens when the view class is in a framework. Select the framework's module. Example with a CocoaPod: HSegmentControl.

当视图类在框架中时会发生这种情况。选择框架的模块。CocoaPod 示例:HSegmentControl。

Example in image is with Cocoapod HSegmentControl

图像中的示例是 Cocoapod HSegmentControl

回答by rezwits

Make sure when you add or rename or move files around especially in folders, that when you add them you:

确保在添加、重命名或移动文件(尤其是在文件夹中)时,添加文件时:

A. Create Groups, not references they don't usually read in.

A. 创建组,而不是他们通常不阅读的参考。

B. Check the boxes for the apporpriate "Product(s) or Target(s)" you want to add the source to.

B. 选中要添加源的适当“产品或目标”的复选框。