即使接口生成器是一个MyClass,我得到一个错误时启动应用程序。
当MyClass是库的一部分时,就会发生这种情况,如果直接在应用程序目标中编译该类则不会发生这种情况。
即使接口生成器是一个MyClass,我得到一个错误时启动应用程序。
当MyClass是库的一部分时,就会发生这种情况,如果直接在应用程序目标中编译该类则不会发生这种情况。
当前回答
在我的例子中,我删除了一个名为“viewController”的类,没有意识到它是用故事板的身份检查器选中的(在顶部的“自定义类”下)。
你只需要在你的身份检查器的自定义类字段中为视图控制器选择正确的类,或者添加一个新类到你的项目中,并选择它作为你的自定义类。
为我工作!
其他回答
这是一个Xcode4缓存问题,删除所有文件夹 /Users/your_user/Library/Application Support/iPhone Simulator/4.3/Applications/
此外,如果你在iPhone上测试时遇到同样的问题,在运行之前删除旧应用程序……
祝你好运。帕斯卡
尽管在运行时打印了“未知类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详细信息检查器,在其中选择类。
在我的情况下,我得到这个错误消息由一个非常愚蠢的错误由我:在接口构建器上,我想设置一个UITableViewCell的标识符,但我意外地键入标识符到'自定义类'的接口构建器条目。
我在....之前制造了1000次细胞
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)
我一直有这个错误与WatchKit一遍又一遍,似乎是当有一个用户界面元素没有绑定到代码中的出口。我猜这在WatchKit中是必需的。
class InterfaceController: WKInterfaceController {
@IBOutlet weak var table: WKInterfaceTable!
}
重要提示:只连接最外层的元素。例如,如果你试图为表中的某些东西提供连接,比如行中的标签,你会得到一个编译器错误,说出口是无效的,不能连接到重复的内容。