且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查UIViewController是否属于目标c中的特定子类?

更新时间:2023-11-28 21:58:46

isKindOfClass:方法指示对象是给定类的实例还是该类的子类的实例。

The isKindOfClass: method indicates whether an object is an instance of given class or an instance of a subclass of that class.

if ([instance1 isKindOfClass:[CustomUIViewController class]]) {
    // code
}

如果要检查对象是否是给定类的实例(但不是a的实例)该类的子类),改为使用 isMemberOfClass:

If you want to check whether an object is an instance of a given class (but not an instance of a subclass of that class), use isMemberOfClass: instead.