isKindOfClass,isMemberOfClass使用备忘

时间:2021-03-26 19:05:47

isMemberOfClass 判断是否是属于这类的实例
isKindOfClass 判断是否是这个类或者这个类的子类的实例

if ([teacher isKindOfClass:[Teacher class]]) {
NSLog(@"teacher 是 Teacher类或Teacher的子类");
} if ([teacher isMemberOfClass:[Person class]]) {
NSLog(@"teacher 是 teacher Teacher类的成员");
}
//遍历子视图
for (UIButton *btn in self.headView.subviews)
{
if ([btn isKindOfClass:[HotWordBtn class]])
{
btn.selected = NO;
}
}