您的位置:首页 > 产品设计 > UI/UE

获取顶层视图控制器UIViewController

2016-03-23 11:42 363 查看
Objective-c版本:

+ (UIViewController *)getCurrentVC
{
UIViewController *RootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *currentVC = RootVC;
while (currentVC.presentedViewController) {
currentVC = currentVC.presentedViewController;
}
return currentVC;
}


Swift版本:

func getCurrentVC()-> UIViewController? {
var RootVC = UIApplication.sharedApplication().keyWindow?.rootViewController
while RootVC?.presentedViewController != nil {
RootVC = RootVC?.presentedViewController
}
return RootVC
}


4000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS-当前控制器