esilver
esilver

Reputation: 28473

Testing for a class method on UIView to maintain backward compatibility

I am trying to use

transitionFromView

Which is a class method on UIView as of iOS 4. All of the following methods return false in the 4.2 simulator:

[UIView respondsToSelector:@selector(transitionFromView:)]
[UIView respondsToSelector:@selector(transitionFromView)]
[[UIView class] respondsToSelector:@selector(transitionFromView)]
[[UIView class] respondsToSelector:@selector(transitionFromView:)]

Other articles on Stack suggest that one of the first two methods should have returned true. What is the appropriate way to test for this method so it will not crash when runing iOS 3?

Thanks.

Upvotes: 0

Views: 837

Answers (2)

Joe
Joe

Reputation: 57179

You are missing part of the selector for the UIView. You want to use the following

BOOL responds = [[UIView class] respondsToSelector:@selector(transitionFromView:toView:duration:options:completion:)];

Upvotes: 3

GendoIkari
GendoIkari

Reputation: 11914

respondsToSelector: is an instance method, not a class method. You should be calling it on a specific instance of a UIView.

Upvotes: 0

Related Questions