如何检查rootViewController是否属于特定类?

时间:2011-09-28 11:57:10

标签: iphone ios

我想知道导航控制器堆栈中的rootViewController是否属于特定类。怎么做这样的事情?

求助,

的Stephane

5 个答案:

答案 0 :(得分:11)

你去哥们

id rootController = [self.navigationController rootViewController];
if([rootController isKindOfClass:[YourDesiredController class]]){
  //do something
 }

答案 1 :(得分:1)

导航控制器根视图控制器是

id rootVC = [[navigationController viewControllers] objectAtIndex:0];

然后查看 rootVC

if ([rootVC isKindOfClass:[YourClass class]]) {

答案 2 :(得分:0)

您可以通过以下方式查看课程:

if ([rootViewController isKindOfClass:[YourClass class]]){

}else if ([rootViewController isKindOfClass:[AnotherClass class]]){

}else{
}

答案 3 :(得分:0)

也许你可以使用方法isKindOfClass

[rootViewController isKindOfClass: [RootViewController class]];

答案 4 :(得分:0)

如何查看当前的rootViewController并在if statement

中使用它
// Get your current rootViewController
NSLog(@"My current rootViewController is: %@", [[[UIApplication sharedApplication].delegate.window.rootViewController class]);

// Use in an if statement
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
if ([rootViewController isKindOfClass:[MyViewController class]])
{
    NSLog(@"Your rootViewController is MyViewController!!");
}