• 获取当前最顶层的ViewController


     1 - (UIViewController *)topViewController {
     2     UIViewController *resultVC;
     3     resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
     4     while (resultVC.presentedViewController) {
     5         resultVC = [self _topViewController:resultVC.presentedViewController];
     6     }
     7     return resultVC;
     8 }
     9 
    10 - (UIViewController *)_topViewController:(UIViewController *)vc {
    11     if ([vc isKindOfClass:[UINavigationController class]]) {
    12         return [self _topViewController:[(UINavigationController *)vc topViewController]];
    13     } else if ([vc isKindOfClass:[UITabBarController class]]) {
    14         return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
    15     } else {
    16         return vc;
    17     }
    18     return nil;
    19 }
    20 使用方法
    21 
    22 UIViewController *topmostVC = [self topViewController];
  • 相关阅读:
    Redis
    vscode
    uget + aria2
    Nodejs 安装
    NPM
    ?Swift获取手机设备信息
    C语言的32个关键字
    MVC-Html.Label(TextBox、TextArea、RadioButton、CheckBox)
    常用正则表达式
    MVC-Razor引擎布局
  • 原文地址:https://www.cnblogs.com/-yun/p/7416779.html
Copyright © 2020-2023  润新知