简体   繁体   English

检查类responsesToSelector是否不起作用

[英]Checking if Class respondsToSelector not working

The following line compiles fine but incorrectly returns false in iOS 8. Why? 以下行可正常编译,但在iOS 8中错误地返回false。为什么?

[[NSLayoutConstraint class] respondsToSelector:@selector(setActive:)]

However, the following correctly returns true - 但是,以下正确返回true-

[self.heightLayoutConstraint respondsToSelector:@selector(setActive:)]

where self.heightLayoutConstraint is of type NSLayoutConstraint . 其中self.heightLayoutConstraint的类型为NSLayoutConstraint

setActive: is not a class method on NSLayoutConstraint , so the return value is correct: the class itself does not respond to that selector. setActive:不是NSLayoutConstraint上的类方法,因此返回值正确:类本身不响应该选择器。

I think you're looking for the class method +instancesRespondToSelector: 我认为您正在寻找类方法+instancesRespondToSelector:

[NSLayoutConstraint instancesRespondToSelector:@selector(setActive:)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM