當(dāng)我在使用DNSPageView框架的時候發(fā)現(xiàn)子控制器,沒辦法 push, 不知道什么原因,可能是沒有獲取到導(dǎo)航欄,我們通過UIApplication可以獲取到當(dāng)前控制器的導(dǎo)航欄來 push 出一個新的控制器
func getNavigationController()-> UINavigationController {
var parent: UIViewController?
if let window = UIApplication.shared.delegate?.window,let rootVC = window?.rootViewController {
parent = rootVC
while (parent?.presentedViewController != nil) {
parent = parent?.presentedViewController!
}
if let tabbar = parent as? UITabBarController ,let nav = tabbar.selectedViewController as? UINavigationController {
return nav
}else if let nav = parent as? UINavigationController {
return nav
}
}
return UINavigationController()
}
使用
let navigationController = getNavigationController()
navigationController.pushViewController(vc, animated: true)