获取当前活动的navigationcontroller

/**

*  获取当前活动的navigationcontroller

*

*  @return <#return value description#>

*/

- (UINavigationController *)navigationViewController {

    UIWindow *window = [UIApplication sharedApplication].keyWindow;

    if ([window.rootViewController isKindOfClass:[UINavigationController class]]) {

        return (UINavigationController *)window.rootViewController;

    } else if ([window.rootViewController isKindOfClass:[UITabBarController class]]) {

        UIViewController *selectVc = [((UITabBarController *)window.rootViewController)selectedViewController];

        if ([selectVc isKindOfClass:[UINavigationController class]]) {

            return (UINavigationController *)selectVc;

        }

    }

    return nil;

}

你可能感兴趣的:(获取当前活动的navigationcontroller)