Unrecognized selector UIDeviceRGBColor countByEnumeratingWithState:objects:count:

北慕城南 提交于 2019-12-10 01:48:20

问题


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'"

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.

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.

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.

Thanks

Michel Colman


回答1:


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:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor length]: unrecognized selector sent to instance 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:

  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)

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.




回答2:


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!



来源:https://stackoverflow.com/questions/39318191/unrecognized-selector-uidevicergbcolor-countbyenumeratingwithstateobjectscount

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!