【swift|swift 获取当前viewcontroller (rootVC)】xcode 报错
whose view is not in the window hierarchy!
也就是你现在的Present的视图并不是Windows视图
///获取当前控制器
func currentVc() ->UIViewController{
var vc = UIApplication.shared.keyWindow?.rootViewControllerif (vc?.isKind(of: UITabBarController.self))! {
vc = (vc as! UITabBarController).selectedViewController
}else if (vc?.isKind(of: UINavigationController.self))!{
vc = (vc as! UINavigationController).visibleViewController
}else if ((vc?.presentedViewController) != nil){
vc =vc?.presentedViewController
}return vc!
}
推荐阅读
- OC编程|OC Swift NotificationCenter通知
- Swift 字典 Dictionary基本用法
- swiftc
- 时间戳和字符串之间转换 Swift
- Other|全国银行SWIFT代码查询
- Swift|以太坊Web3Swift常用方法使用
- ios|CocoaPods pod install / pod update 更新太慢 卡死 问题解决