xcode 无法识别的选择器 UIDeviceRGBColor countByEnumerateWithState:objects:count:

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

Unrecognized selector UIDeviceRGBColor countByEnumeratingWithState:objects:count:

iosobjective-cxcodeios10xcode8-beta6

提问by Michel Colman

I know this is kind of a dupe, but I don't have enough reputation yet to comment on the original post and, while I don't have an answer, I do have more useful information (a concrete example). Moderators, feel free to move this to the proper location.

我知道这是一种骗局,但我还没有足够的声誉来评论原始帖子,虽然我没有答案,但我确实有更多有用的信息(一个具体的例子)。版主,请随意将其移至适当的位置。

When compiling my code using the latest XCode 8 beta 6 (iOS 10 SDK), I get an exception "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x600000071340'"

使用最新的 XCode 8 beta 6 (iOS 10 SDK) 编译我的代码时,出现异常“由于未捕获的异常‘NSInvalidArgumentException’而终止应用程序,原因:‘-[UIDeviceRGBColor countByEnumerateWithState:objects:count:]: unrecognized selector sent to实例 0x600000071340'"

This happens during the call:

这发生在通话期间:

    auto viewController = [[[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

I have isolated the problem by whittling down my project to the bare minimum that will compile and still exhibit the problem. You can download it here:

我通过将我的项目缩减到将编译并仍然显示问题的最低限度来隔离问题。您可以在这里下载:

Example project

示例项目

Note that I took out lots of code, nearly all classes are gone, which results in a lot of warnings (not errors) for nonexistent classes referenced from the xib. But that doesn't matter, the code still compiles and runs just fine with the iOS 9 SDK. After compiling with the iOS 10 sdk, however, it crashes both in the simulator and on devices running iOS 9.

请注意,我取出了大量代码,几乎所有类都消失了,这导致从 xib 引用的不存在类的大量警告(不是错误)。但这并不重要,代码在 iOS 9 SDK 上仍然可以编译和运行。然而,在使用 iOS 10 sdk 编译后,它在模拟器和运行 iOS 9 的设备上都会崩溃。

You can work around the problem by changing "#if 0" into "#if 1" in the file "HackForUnrecognizedSelectorInIOS10.m". This adds a category defining the missing selectors for UIColor. But obviously you can't add that to shipping code, it's just a temporary stopgap measure to continue developing.

您可以通过将“HackForUnrecognizedSelectorInIOS10.m”文件中的“#if 0”更改为“#if 1”来解决该问题。这为 UIColor 添加了一个定义缺失选择器的类别。但显然你不能将它添加到运输代码中,这只是继续开发的临时权宜之计。

I filed a bug report (28153870). But if anyone has any more information on how to avoid this problem without ugly hacks, any information is welcome.

我提交了错误报告 (28153870)。但是,如果有人有关于如何在没有丑陋黑客的情况下避免此问题的更多信息,欢迎提供任何信息。

Thanks

谢谢

Michel Colman

米歇尔·科尔曼

回答by alanlo

When I try to compile and run my project with the same configuration (XCode 8 beta 6, iOS 10 SDK), I encountered a similar issue, except that my error message was:

当我尝试使用相同的配置(XCode 8 beta 6、iOS 10 SDK)编译和运行我的项目时,我遇到了类似的问题,只是我的错误消息是:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x600000479280'

*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIDeviceRGBColor 长度]:无法识别的选择器发送到实例 0x600000479280”

And I noticed that this issue only occurs when the view is init by using interface files, i.e. Xib and Nib. I solved this issue by:

我注意到这个问题只有在使用接口文件初始化视图时才会发生,即 Xib 和 Nib。我通过以下方式解决了这个问题:

  1. Open your interface file, in the right panel, navigate to the File Inspector tab.

  2. Change the attribute highlighted to "iOS 7.0 and Later" (or whatever iOS version later) enter image description here

  1. 打开您的界面文件,在右侧面板中,导航到 File Inspector 选项卡。

  2. 将突出显示的属性更改为“iOS 7.0 及更高版本”(或更高版本的任何 iOS 版本) 在此处输入图片说明

Then compile and run your project again, this should fix your issue, though I am not sure about the reason behind this. I tried the same with your sample project and it solves the issue too.

然后再次编译并运行您的项目,这应该可以解决您的问题,尽管我不确定这背后的原因。我对您的示例项目进行了相同的尝试,它也解决了该问题。

回答by XIII

In my case, I needed to change the project deployment target to 8.0 in the product general settings. Thanks to the hint from the accepted answer!

就我而言,我需要在产品常规设置中将项目部署目标更改为 8.0。感谢已接受答案的提示!