Ios 比较类给出了不正确的输出
我正在使用下面的代码检查视图控制器Ios 比较类给出了不正确的输出,ios,objective-c,compare,Ios,Objective C,Compare,我正在使用下面的代码检查视图控制器 NSLog(@"addProductClicked 1===%@", self.class); NSLog(@"addProductClicked 2===%@", [CategoriesViewController class]); if ([self.class isKindOfClass:[CategoriesViewController class]]) { NSLog(@"you go it right"); } else {
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
知道出了什么问题吗
为了更新,下面是我定义的视图控制器
@interface CategoriesViewController : GlobalViewController {
现在,在
GlobalViewController
中,我有了我在上面检查的方法…这是错误的比较。对该类的对象调用isKindOfClass:
。大概是这样的:
CategoriesViewController *obj = [[CategoriesViewController alloc] init];
[obj isKindOfClass:CategoriesViewController];
在您的情况下,您可能需要检查
self
要进行类检查的变量应该作为对象而不是类传入
if ([self isKindOfClass:[CategoriesViewController class]]) {
NSLog(@"you go it right");
} else {
NSLog(@"you go it wrong");
}