tags:

views:

38

answers:

2

I need to check which UIViewController is active so I have implemented some cases depending upon the result.

[self.navigationController.visibleViewController className]

This always returns null.

I am checking with this statement:

if([iDetailController isKindOfClass:[IDetailController class]])

but it fails, kindly help me if I am doing something wrong here.

A: 

Use the following method:

if ([self isMemberOfClass:[IDetailController class]]) {

CFShow(@"Yep, it's the IDetailController controller"); }

isMemberOfClass tells you if the instance is an exact instance of that class. There's also isKindOfClass:

if ([self isKindOfClass:[BaseView class]]) {

CFShow(@"This will log for all classes that extend BaseView");`

}

isKind tests that the class is a extension of a certain class.

iPhoneDev
+1  A: 

Use [self.navigationController.topViewController class] to get active view controller's class. So if ([self.navigationController.topViewController isMemberOfClass:[IDetailController class]]) {...} should work.

kpower