1、判断当前VC的上一个VC是否是什么类型

NSInteger i = [self.navigationController.childViewControllers   indexOfObject:self];

    if (!i) return NO;

    i--;

    id preVC = self.navigationController.childViewControllers[i];

    NSString *className = [NSString stringWithUTF8String:object_getClassName(preVC)];

    if ([className isEqualToString:@""]) return YES;

    return NO;

 

 

2、获取上一个页面

if (![self isEqual:self.navigationController.viewControllers.firstObject] &&

                         self.navigationController.viewControllers.count > 1) {

                         

                         UIViewController *mVC;

                         mVC = self.navigationController.viewControllers[self.navigationController.viewControllers.count-2];//获取上一个页面

                         if (mVC) {

                             //dosomething

                         }

                     }

 

 

 

3、

获取当前活跃页面的根控制器

- (UIViewController *)getCurrentVC

{

    UIViewController *result = nil;

    

    UIWindow * window = [[UIApplication sharedApplication] keyWindow];

    if (window.windowLevel != UIWindowLevelNormal)

    {

        NSArray *windows = [[UIApplication sharedApplication] windows];

        for(UIWindow * tmpWin in windows)

        {

            if (tmpWin.windowLevel == UIWindowLevelNormal)

            {

                window = tmpWin;

                break;

            }

        }

    }

    

    UIView *frontView = [[window subviews] objectAtIndex:0];

    id nextResponder = [frontView nextResponder];

    

    if ([nextResponder isKindOfClass:[UIViewController class]])

        result = nextResponder;

    else

        result = window.rootViewController;

    

    return result;

}

 

posted on 2016-11-29 17:18  fatal-奚山遇白  阅读(196)  评论(0)    收藏  举报