xcode 接口生成器文件中的未知类****
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19401783/
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
Unknown Class **** in Interface Builder file
提问by Fogmeister
I added a UIView xib file using the root class of MyView
.
我使用MyView
.
I created it in the wrong place and so moved it in the project. Same project just a different folder/group.
我在错误的地方创建了它,所以在项目中移动了它。同一个项目只是不同的文件夹/组。
I then had a problem when running saying...
然后我在跑步时遇到了问题说...
Unknown Class MyView in Interface Builder file
Unknown Class MyView in Interface Builder file
I couldn't work out what was wrong so I have now deleted the files both from the project and from the directory.
我不知道出了什么问题,所以我现在已经从项目和目录中删除了文件。
I've done a search using SublimeText2 for the string "MyView" and it doesn't exist anywhere in the project.
我已经使用 SublimeText2 对字符串“MyView”进行了搜索,但它在项目中的任何地方都不存在。
I've reset the simulator, cleaned the project and the build folder and deleted derived data.
我重置了模拟器,清理了项目和构建文件夹并删除了派生数据。
Still getting the same error.
仍然得到同样的错误。
Any ideas what I can do now?
任何想法我现在可以做什么?
采纳答案by Fogmeister
OK, so I deleted all references to the class causing the problem but still nothing.
好的,所以我删除了对导致问题的类的所有引用,但仍然没有。
However, I also had a UIViewController subclass called MyViewController
. This wasn't being loaded in any IB file so I don't know how it was causing the problem.
但是,我还有一个 UIViewController 子类,称为MyViewController
. 这没有被加载到任何 IB 文件中,所以我不知道它是如何导致问题的。
I changed the name to MyOtherViewController
.
我把名字改成了MyOtherViewController
。
Build - Run - works.
构建 - 运行 - 有效。
I don't know how or why but it works now.
我不知道如何或为什么,但它现在有效。
回答by ChikabuZ
Sometimes IBuilder missed customModule="AppName" customModuleProvider="target"
有时 IBuilder 会错过 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 Xeieshan
Go to View -> Utilities Goto File Inspector of .m file
转到查看 -> 实用工具转到 .m 文件的文件检查器
Open the Target Membership section and make sure that your target is selected for this .m-file
打开 Target Membership 部分并确保为此 .m 文件选择了您的目标
回答by Enrico Susatyo
If you have multiple targets in your Xcode project, make sure that the class the was mentioned in the error file is compiled for the target you're testing with as well.
如果您的 Xcode 项目中有多个目标,请确保错误文件中提到的类也是为您正在测试的目标编译的。
回答by bazik
appcode is very stubborn in keeping the old xib cached somewhere, and if you have the cached xib and it has the same name that your controller it will try to load it on start.
appcode 非常固执地将旧的 xib 缓存在某处,如果您有缓存的 xib 并且它与您的控制器具有相同的名称,它将尝试在启动时加载它。
what I do after deleting a .xib:
删除 .xib 后我会做什么:
- delete app from the device
- clean build folder in app code
- invalidate caches and restart, kill appcode before it starts
- delete derived data in xcode
- start appcode
- 从设备中删除应用程序
- 清理应用程序代码中的构建文件夹
- 使缓存无效并重新启动,在启动之前杀死 appcode
- 删除 xcode 中的派生数据
- 启动应用程序代码
step 4 shouldn't be necessary, but my feeling is that without it I am still seeing the deleted .xib
第 4 步应该没有必要,但我的感觉是没有它我仍然看到已删除的 .xib
回答by winner.ktw
回答by Nitin Alabur
This happened to me when I renamed the custom view class, and the module (in the identity inspector when the view is selected) was blank. It remained blank because Xcode didn't autocomplete the custom class name, hence it left the module blank. All I had to do was re-enter the class name after a build, and then it autocompleted, and selected to appropriate module (Current - Target)
当我重命名自定义视图类时,这发生在我身上,并且模块(在选择视图时在身份检查器中)是空白的。它保持空白,因为 Xcode 没有自动完成自定义类名,因此它将模块留空。我所要做的就是在构建后重新输入类名,然后它会自动完成,并选择到适当的模块(当前 - 目标)
回答by Genki
I had the same issue when I had multiple class declarations in one file. What I did is I declared a UITableViewCell subclass in one of my view controllers, and forgot to put the UITableViewCell subclass' @implementation in the view controller's .m file.
当我在一个文件中有多个类声明时,我遇到了同样的问题。我所做的是在我的一个视图控制器中声明了一个 UITableViewCell 子类,但忘记将 UITableViewCell 子类'@implementation 放在视图控制器的 .m 文件中。
回答by Robin
As my experience, All solutions above had not worked out. Then I had to re-input the custom class in all strayed Xibs. As an amazing result, it just succeeded and what I had done reconnected the lost connection between @interface and IB. Hope to be useful.
根据我的经验,上述所有解决方案都没有奏效。然后我不得不在所有杂散的 Xib 中重新输入自定义类。令人惊讶的结果是,它刚刚成功,我所做的重新连接了@interface 和 IB 之间丢失的连接。希望有用。