Sagar...
Sagar...

Reputation: 1062

How to check which UIViewController is active

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.

Upvotes: 0

Views: 2126

Answers (2)

kpower
kpower

Reputation: 3891

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

Upvotes: 1

iPhoneDev
iPhoneDev

Reputation: 3015

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.

Upvotes: 0

Related Questions