2010-08-04 77 views
0

我需要檢查哪個UIViewController處於活動狀態,因此我根據結果實施了一些情況。如何檢查哪個UIViewController處於活動狀態

[self.navigationController.visibleViewController className] 

這總是返回null。

我這個說法檢查:

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

,但它沒有,請幫助我,如果我在這裏做得不對。

回答

0

使用以下方法:

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

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

isMemberOfClass告訴你,如果實例是類的確切實例。還有isKindOfClass:

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

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

}

isKind測試,該類是某一類的擴展。

1

使用[self.navigationController.topViewController class]來獲得活動視圖控制器的類。所以if ([self.navigationController.topViewController isMemberOfClass:[IDetailController class]]) {...}應該工作。

相關問題