ios 界面生成器中的未知类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38846538/
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
提问by Max
I know that there are a lot of questions on this subject but I've tried most of them to try and figure it out with no success.
我知道关于这个主题有很多问题,但我已经尝试了其中的大部分来尝试解决问题,但没有成功。
the problem: at first I couldn't add my class from the assistant editor cause the custom class didn't pick it up.
问题:起初我无法从助理编辑器添加我的类,因为自定义类没有选择它。
- I made sure the calls inherits from uiviewcontroller
- I made sure the class is added to the target
- I tried to remove the class file and re-add it back
- finally I've added the class through the storyboard xml and it appeared in the custom class
- 我确保调用继承自 uiviewcontroller
- 我确保该类已添加到目标
- 我试图删除类文件并将其重新添加回来
- 最后我通过 storyboard xml 添加了类,它出现在自定义类中
Now I'm trying to connect my buttons, views etc to its outlets. It seems like they are connected but when running the app and opening that view controller the app crashes and the debugger prints: "Unknown class xxx in Interface Builder file." and than "this class is not key value coding-compliant for the key btnMenu."
现在我试图将我的按钮、视图等连接到它的插座。似乎它们已连接,但是当运行应用程序并打开该视图控制器时,应用程序崩溃并且调试器打印:“Interface Builder 文件中的未知类 xxx。” 而不是“这个类不是键 btnMenu 的键值编码兼容。”
I've checked:
我检查过:
- That connection inspector is properly set (no error in the outlets there)
- Tried to delete derived data
- Clean project
- Re-install the app
- 该连接检查器设置正确(那里的插座没有错误)
- 试图删除派生数据
- 清洁工程
- 重新安装应用
I even tried restarting my mac and of course no success.
我什至尝试重新启动我的 mac,当然没有成功。
can anyone shad some light here? thanks.
任何人都可以在这里遮光吗?谢谢。
回答by Anthony Scott
I just had this happen with a UIViewController subclass (with Xcode 9 beta 2 & Swift 4) and the solution was to tick 'Inherit from Target' where I set the Custom Class in IB.
我刚刚在 UIViewController 子类(使用 Xcode 9 beta 2 和 Swift 4)中发生了这种情况,解决方案是勾选“从目标继承”,我在 IB 中设置自定义类。
If your view happens to be in a .bundle
file (such as for a framework/static library) that gets copied to a different target, you'll want to set an explicit module target for each xib/storyboard class rather than having it inherit from the target that's hosting it.
如果您的视图恰好位于.bundle
被复制到不同目标的文件(例如框架/静态库)中,您将需要为每个 xib/storyboard 类设置一个显式模块目标,而不是让它从托管它的目标。
回答by Mr. Desai
回答by Shihab Uddin
After I checked the tick mark called "Inherit Module From Target" in Custom Class in View Controller Section, it works fine. Can Follow the image.
在查看控制器部分的自定义类中检查名为“从目标继承模块”的刻度线后,它工作正常。可以跟着图。
To find this > Select your view controller yellow button> then click "Show Identity Inspector" > then checked the tick markcalled "Inherit Module From Target"
为了找到这个>选择您的视图控制器黄色按钮>然后单击“显示身份检查”>选中,则刻度被称为“继承模块从目标”
回答by travdu
What @Anthony Scott mentioned is true until you have Framework_A dependent on Framework_B and class is from Framework_B :) Then you need to deselect checkbox and provide Module which contains given class. Thanks for the question btw. I am using Commons framework for other frameworks and it helped me to realize this ;) For those who develop custom Cocoa Touch Frameworks this can be helpful.
@Anthony Scott 提到的内容是正确的,直到您将 Framework_A 依赖于 Framework_B 并且类来自 Framework_B :) 然后您需要取消选中复选框并提供包含给定类的模块。谢谢你的问题顺便说一句。我正在将 Commons 框架用于其他框架,它帮助我实现了这一点;) 对于那些开发自定义 Cocoa Touch 框架的人来说,这可能会有所帮助。
回答by Ben
I had this problem with a custom UIView I was testing, where the UIView was in a framework. I had created a simple app, created a UIView in the Storyboard's default ViewController and set its class to MyCustomView. I always got the "Unknown class in interface builder" error when the app launched. I was importing my framework, and I checked in the built product that the framework was there.
我在测试自定义 UIView 时遇到了这个问题,其中 UIView 位于框架中。我创建了一个简单的应用程序,在 Storyboard 的默认 ViewController 中创建了一个 UIView,并将其类设置为 MyCustomView。应用程序启动时,我总是收到“界面构建器中的未知类”错误。我正在导入我的框架,并且我检查了构建的产品,该框架在那里。
The problem was that my test app code never actually used the framework. Even though the Storyboard referenced it, I guess it never got loaded. When I added a [MyCustomView load];
into the test app code, it all worked.
问题是我的测试应用程序代码从未真正使用过该框架。尽管 Storyboard 引用了它,但我想它从未加载过。当我将 a 添加[MyCustomView load];
到测试应用程序代码中时,一切正常。
回答by Natasha
If you are trying to assign a class to a ViewController, please make sure the class you created is inheriting a UIViewController. The only reason that xCode won't recognize your class is where it is a different type of instance, let's say, may be a UITableViewController type.
如果您尝试将类分配给 ViewController,请确保您创建的类继承了 UIViewController。xCode 无法识别您的类的唯一原因是它是不同类型的实例,比如说,可能是 UITableViewController 类型。
Please check the inheritence of your class first.
请先检查您的类的继承。
回答by tesla
For those who encounter this problem but with a system class like PKCanvasView
or ARView
, in a storyboard.
对于那些遇到此问题但在故事板中使用系统类(如PKCanvasView
或ARView
)的人。
After you've set view's Custom Class
to any of those system classes, make sure the Module
is set to None
. Next go to target's Link Binary with Libraries
in Build Phases
and manually link the framework which contains that class. One last step is to do a clean and remove derived data (it's critical otherwise the problem won't float away).
将视图设置Custom Class
为任何这些系统类后,请确保将Module
设置为None
. 接下来转到 target's Link Binary with Libraries
inBuild Phases
并手动链接包含该类的框架。最后一步是清理并删除派生数据(这很关键,否则问题不会消失)。
回答by jhonkaman
I ran into this error because I accidentally saved my class file to the Base.lproj folder when I created it.
我遇到了这个错误,因为我在创建它时不小心将我的类文件保存到 Base.lproj 文件夹中。
I fixed the error by right-clicking the file in the Project Navigator and deleting the reference to it. I then moved the file through Finder to the correct folder. Then I right-clicked the main group in the Project Navigator and clicked Add Files to "GroupName"...
and selected the class and clicked the Add
button.
我通过右键单击项目导航器中的文件并删除对它的引用来修复错误。然后我通过 Finder 将文件移动到正确的文件夹。然后我在项目导航器中右键单击主组,然后单击Add Files to "GroupName"...
并选择类并单击Add
按钮。
After that the error went away.
在那之后,错误消失了。
回答by Max
ok so i dont know how and why, but, i did (AGAIN) what i already tried before which is:
好的,所以我不知道如何以及为什么,但是,我(再次)做了我之前已经尝试过的事情:
- deleting the class
- creating the same class with new name
- removed the scene and recreated it in the storyboard
- connected it all (in the same usual way!!!)
- 删除班级
- 使用新名称创建相同的类
- 删除场景并在故事板中重新创建它
- 连接所有(以相同的通常方式!!!)
now it seems that Xcode knows my class.... i still don't know what was the problem but i guess it has something to do with the linker.
现在看来 Xcode 知道我的班级……我仍然不知道问题出在哪里,但我想这与链接器有关。
回答by Mo Iisa
Check the name of your class. Make sure that it corresponds to the class to which you have assigned your ViewController in the property inspector.
检查您的班级名称。确保它对应于您在属性检查器中分配给 ViewController 的类。