The various UIAppearance proxy instances do not respond to selectors (as they are a proxy of their relevant types, not an actual instance of it), as discussed in this question and answer.
This makes it impossible to test for new iOS 6 features of the Appearance API. e.g. this appearance change will never execute as the code within the if check always returns false, even on iOS 6, because the instance it is checking is not a real instance but an appearance proxy.
if ( UINavigationBar.Appearance.RespondsToSelector( new Selector("setShadowImage:")))
UINavigationBar.Appearance.ShadowImage = new UIImage();
The answer linked says to use the instancesRespondToSelector method. However I can’t find it anywhere in the MT APIs. Am I just blind, or is there a different way to achieve this in MT?
There are few differences between both
respondsToSelector:andinstancesRespondToSelector:, here’s a good description, except that the later is astaticmethod.The answer, from your link, uses
instancesRespondToSelector:on the real type, not itsAppearanceproxy. You can get the same result usingRespondsToSelectorthat is already available in MonoTouch.IOW it assume that if
setShadowImage:is available then you can access it’s proxy. That’s not true for features that existed beforeUIAppearancewas available (code might work but the result won’t match your expectations).In many cases you can enable/disable several features by doing a single version check like this:
Right now
instancesRespondToSelector:is not part of the public API that MonoTouch provide (it would need to be bound in every type, at least in done using generated bindings). However it’s not hard to implement if you want it. You can use this code:And you can turn it into a method if you need it in several places. Keep in mind that it will return the same answer as
RespondsToSelector(for your specific question).