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
422 0
|
JavaScript 前端开发 Android开发
iOS中UIWebView的使用详解
iOS中UIWebView的使用详解
199 0
iOS中UIWebView的使用详解
|
iOS开发
iOS UIButton解读
iOS UIButton解读
180 0
|
JavaScript Android开发 iOS开发
iOS UIWebView使用
1. 加载 WebView可直接加载.mp4,.pdf,.html,.doc等格式文件。 @interface ViewController () @property (nonatomic, strong) UIWebView *webView; @e...
1135 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 视图控制器负责页面的创建、事件处理等。
1414 0
|
iOS开发 Swift 索引
iOS - UIView
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIView : UIResponder @available(iOS 2.0, *) public class UIView : UIResponder, NSCoding,...
1305 0
|
iOS开发 Swift
iOS - UIDatePicker
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIDatePicker : UIControl @available(iOS 2.0, *) public class UIDatePicker : UIControl, NSCoding UIDatePicker 是 UIKit 控件中提供日期和时间选择的控件。
1032 0