如何检查UIViewController是否属于目标c中的特定子类? [英] How to check if a UIViewController is of a particular sub-class in objective c?
本文介绍了如何检查UIViewController是否属于目标c中的特定子类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够检查UIViewController的类型,看看它是否属于某种类型
I want to be able to check the type of a UIViewController to see if it is of a certain type like this
c code
if (typeof(instance1) == customUIViewController)
{
customUIViewController test = (customViewController)instance1;
// do more stuff
}
推荐答案
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.
这篇关于如何检查UIViewController是否属于目标c中的特定子类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文