码迷,mamicode.com
首页 > 其他好文 > 详细

得到当前活动的controller

时间:2014-08-04 13:47:17      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   div   log   window   res   c   

UIWindow+PazLabs.h (header file)

#import <UIKit/UIKit.h>

@interface UIWindow (PazLabs)

- (UIViewController *) visibleViewController;

@end

  

UIWindow+PazLabs.m (implementation file)

#import "UIWindow+PazLabs.h"

@implementation UIWindow (PazLabs)

- (UIViewController *)visibleViewController {

    UIViewController *rootViewController = self.rootViewController;

    return [UIWindow getVisibleViewControllerFrom:rootViewController];

}

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

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

        return [UIWindow getVisibleViewControllerFrom:[((UINavigationController *) vc) visibleViewController]];

    } else if ([vc isKindOfClass:[UITabBarController class]]) {

        return [UIWindow getVisibleViewControllerFrom:[((UITabBarController *) vc) selectedViewController]];

    } else {

        if (vc.presentedViewController) {

            return [UIWindow getVisibleViewControllerFrom:vc.presentedViewController];

        } else {

            return vc;

        }

    }

}

@end

  

得到当前活动的controller,布布扣,bubuko.com

得到当前活动的controller

标签:blog   io   ar   div   log   window   res   c   

原文地址:http://www.cnblogs.com/dokaygang128/p/3889745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!