我正在使用下面的代码来检查 View Controller 。
NSLog(@"addProductClicked 1===%@", self.class);
NSLog(@"addProductClicked 2===%@", [CategoriesViewController class]);
if ([self.class isKindOfClass:[CategoriesViewController class]]) {
NSLog(@"you go it right");
} else {
NSLog(@"you go it wrong");
}
我得到的输出如下。
addProductClicked 1===CategoriesViewController
addProductClicked 2===CategoriesViewController
you go it wrong
知道出了什么问题吗?
更新一下,下面是我定义的 View Controller ...
@interface CategoriesViewController : GlobalViewController {
现在在 GlobalViewController
中,我有方法在上面检查...
最佳答案
要进行类检查的变量应作为对象而不是类传入。
if ([self isKindOfClass:[CategoriesViewController class]]) {
NSLog(@"you go it right");
} else {
NSLog(@"you go it wrong");
}
关于ios - 比较类给出了不正确的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32987501/