1. 程式人生 > >獲取當前顯示的viewController

獲取當前顯示的viewController

//獲取當前的UIViewController 

+ (NSString *)getViewController

{

UIViewController *resultVC = [selftopViewController:[[UIApplicationsharedApplication].keyWindowrootViewController]];

while (resultVC.presentedViewController) {

        resultVC = [selftopViewController:resultVC.presentedViewController];

    }

NSLog

(@"當前viewController===========%@",resultVC);

returnresultVC;

}

+ (UIViewController *)topViewController:(UIViewController *)vc {

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

return [self topViewController:[(UINavigationController *)vc topViewController]];

    } elseif ([vc isKindOfClass:[

UITabBarController class]]) {

return [selftopViewController:[(UITabBarController *)vc selectedViewController]];

    } else {

return vc;

    }

returnnil;

}

iPhone 透明手機殼+全包手機膜+home鍵透明貼+攝像頭保護膜 = 9.9元