即使接口生成器是一个MyClass,我得到一个错误时启动应用程序。
当MyClass是库的一部分时,就会发生这种情况,如果直接在应用程序目标中编译该类则不会发生这种情况。
即使接口生成器是一个MyClass,我得到一个错误时启动应用程序。
当MyClass是库的一部分时,就会发生这种情况,如果直接在应用程序目标中编译该类则不会发生这种情况。
当前回答
我有“未知类RateView在接口生成器”,其中RateView是UIView的子类。我已经在Storyboard场景中放置了一个UIView,并将自定义类字段更改为RateView。尽管如此,这个错误还是出现了。
为了调试,我将我的类的名称改为RateView2,并将所有引用更改为匹配,除了UIView的自定义类字段。错误消息仍然像以前一样出现,RateView是缺失的类。这确认了错误消息与Custom类字段的值相关。我将这个值更改为RateView2,错误消息更改为“未知类RateView2在接口生成器”。某种程度上的进步。
最后,我在文件检查器中检查源代码文件本身。在那里,我发现源代码文件(我从教程中复制的)与我的Target没有关联。换句话说,它没有目标会员。我选中了使类的源代码文件成为目标应用程序成员的复选框,错误消息消失了。
其他回答
In my case I got this error because I'd tried to save some work by creating a new project and then deleting several of the source files and copying over the source files of the same name from the working project. I also copied my MainStoryBoard file which was looking for my RootViewController. However, when I had deleted the original RootViewController and then added in the RootViewController from the previous product, evidently the Add Files operation failed to "check" the target box as suggested above. By merely visting all of the newley imported ".m" files and making sure that the target membership box was checked, all was well. I think what was happening was that the storyboard file was looking for a class that had been "excluded" from the link because the target membership was unchecked. Making sure the required files for the target are so designated in the target membership in the file inspector did the trick. Thanks Pat! (see above)
这让我有点抓狂,上面的建议都没有帮助我摆脱这个错误。幸运的是,我只有一个IB对象使用类,所以我只是删除了它,并添加了相同的类指定。错误消失了……
在我的情况下,类不能被找到,因为它是一个类定义在一个框架内的扩展,如下所示:
extension Buttons {
public class MyButton: UIButton {
// ...
}
}
当我从扩展中提取类时,Storyboard最终可以找到类(MyFrameworkButton):
extension Buttons {
public typealias MyButton = MyFrameworkButton
}
public class MyFrameworkButton: UIButton {
// ...
}
发生这种情况是因为.xib有一个陈旧的链接到旧的应用程序委托,它不再存在了。 我是这样修改的:
右键单击.xib并选择“打开为>源代码” 在这个文件中,搜索旧的App委托并将其替换为新的委托
尽管在运行时打印了“未知类MyClass in Interface Builder file.”错误,但这个问题与Interface Builder无关,而是与链接器有关,因为没有代码直接使用它,所以链接器没有链接类。
当.nib数据(从.xib编译)在运行时加载时,MyClass使用字符串引用,但链接器不分析代码功能,只分析代码存在,所以它不知道。由于没有其他源文件引用该类,链接器在生成可执行文件时将其优化为不存在。因此,当Apple的代码试图加载这样一个类时,它无法找到与之相关的代码,并打印警告。
默认情况下,Objective-C目标将默认设置-all_load -ObjC标志,这将保留所有的符号。但我一开始的目标是c++,没有这个。尽管如此,我还是找到了一种方法,使链接器保持侵略性。
我最初使用的黑客是添加一个空的静态例程,如:
+(void)_keepAtLinkTime;
它什么都不做,但我会调用一次,比如:
int main( int argc, char** argv )
{
[MyClass _keepAtLinkTime];
// Your code.
}
这将迫使链接器保留整个类,错误就会消失。
正如jlstrecker在评论中指出的那样,我们实际上并不需要添加_keepAtLinkTime方法。简单地调用一个现有的函数,例如:
[MyClass class];
(只要你是从NSObject派生的)。
当然,您可以在代码的任何位置调用它。我猜它甚至可能是不可访问的代码。这个想法是欺骗链接器,让它认为MyClass在某个地方被使用了,这样它就不会那么积极地优化它。
Xcode 6.3.2和Swift 1.2
快速定义视图。确保重写init(coder aDecoder: NSCoder)。视图控制器的Objective-C定义。还有,梨树上的笔尖。
将模块名称添加到Nib详细信息检查器,在其中选择类。