草庐IT

instanceRespondToSelector

全部标签

ios - instanceRespondToSelector 在不应该返回 true 时返回

我正在编写一个向后兼容iOS6.0的iOS应用程序。在iOS7中,NSString实例方法drawInRect:withAttributes:取代了drawInRect:withFont:lineBreakMode:alignment:。为了确定使用哪种方法,我有以下代码:if([NSStringinstancesRespondToSelector:@selector(drawInRect:withAttributes:)]){NSMutableParagraphStyle*textStyle=[[NSMutableParagraphStyledefaultParagraphStyle

ios - instanceRespondToSelector 的等效类是什么?

检查类方法是否由类实现的最简单方法是什么?比如UIFont定义了这个方法:+(UIFont*)preferredFontForTextStyle:(NSString*)styleNS_AVAILABLE_IOS(7_0);我不能在这里使用instancesRespondToSelector:,因为preferredFontForTextStyle:不是实例方法,而是类方法。我看到了class_getClassMethod,但是……真的吗?objc/runtime.h? 最佳答案 我会使用:[MyClassrespondsToSele