Reputation: 31637
I am using below code to check view controllers.
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");
}
The output I get is as below.
addProductClicked 1===CategoriesViewController
addProductClicked 2===CategoriesViewController
you go it wrong
Any idea what is going wrong?
Just to update, below is what I have defined my view controller...
@interface CategoriesViewController : GlobalViewController {
Now in GlobalViewController
I have method where I am checking above...
Upvotes: 1
Views: 45
Reputation: 11476
The variable you want to class check should be passed in as an object, not as a class.
if ([self isKindOfClass:[CategoriesViewController class]]) {
NSLog(@"you go it right");
} else {
NSLog(@"you go it wrong");
}
Upvotes: 1
Reputation: 38152
Thats is wrong comparison. You call isKindOfClass:
on the object of that class. Something like this:
CategoriesViewController *obj = [[CategoriesViewController alloc] init];
[obj isKindOfClass:CategoriesViewController];
In your case you probably want to put a check on self
.
Upvotes: 1