iOS 获取当前ViewController

简介: iOS 获取当前ViewController
+ (UIViewController *)findCurrentViewController {
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    UIViewController *topViewController = [window rootViewController];
    while (true) {
        if (topViewController.presentedViewController) {
            topViewController = topViewController.presentedViewController;
        } else if ([topViewController isKindOfClass:[UINavigationController class]] && [(UINavigationController*)topViewController topViewController]) {
            topViewController = [(UINavigationController *)topViewController topViewController];
        } else if ([topViewController isKindOfClass:[UITabBarController class]]) {
            UITabBarController *tab = (UITabBarController *)topViewController;
            topViewController = tab.selectedViewController;
        } else {
            break;
        }
    }
    return topViewController;
}
目录
相关文章
|
iOS开发
IOS获取 UIWindow
IOS获取 UIWindow
424 0
|
JavaScript 前端开发 Android开发
iOS中UIWebView的使用详解
iOS中UIWebView的使用详解
204 0
iOS中UIWebView的使用详解
|
JavaScript Android开发 iOS开发
iOS UIWebView使用
1. 加载 WebView可直接加载.mp4,.pdf,.html,.doc等格式文件。 @interface ViewController () @property (nonatomic, strong) UIWebView *webView; @e...
1139 0
|
iOS开发 Swift 缓存
iOS - UIViewController
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIViewController : UIResponder @available(iOS 2.0, *) public class UIViewController : UIResponder, NSCoding, UIAppearanceContainer, UITraitEnvironment, UIContentContainer, UIFocusEnvironment 视图控制器负责页面的创建、事件处理等。
1424 0
|
iOS开发 容器 Swift
iOS - UINavigationController
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationController : UIViewController @available(iOS 2.0, *) public class UINavigationController : UIViewController UINavigationController:容器视图控制器的一种,称之为导航视图控制器,导航视图控制器固定高度是 44。
1438 0