4

I solved my problem by using CGColorGetComponents, but I would like to understand exactly what was the reason.

I was doing the following with an instance of UIColor *firstColour :

[firstColour getRed:&r green:&g blue:&b alpha:nil];

This was working perfectly fine on simulator. Then I tested it on my device, and got this error :

UIDeviceRGBColor getRed:green:blue:alpha unrecognized selector sent to instance

After some research on the Internet I found that UIColor is actually replaced by subclasses, like UIDeviceRGBColor. Fine, but shouldn't subclasses work just like UIColor and accept (at least) the same methods ?

I enabled Zombie but apparently this wasn't a memory management issue, like most people say on forums. And I can't find documentation for UIDeviceRGBColor so I don't know how it is supposed to behave. Does someone know why it happened, and above all, if this is likely to happen again with another method ?

Thank you.

4

1 回答 1

7

getRed:green:blue:alpha:UIColor 中的方法从 iOS 5.0 开始可用。最有可能的问题是您的设备具有较旧的操作系统版本,该方法不可用。

在较旧的操作系统上,您可能必须使用/函数从底层CGColorRef结构中检索颜色组件CGColorGetComponentsCGColorGetNumberOfComponents

于 2012-05-22T09:37:07.267 回答